Skip to content

Commit

Permalink
last-hash file replaced with gsettings
Browse files Browse the repository at this point in the history
  • Loading branch information
sulincix committed Dec 6, 2023
1 parent 9a41d99 commit 976e565
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/data/gsettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@
<default>""</default>
<summary>Last session</summary>
</key>
<key type="s" name="last-hash">
<default>""</default>
<summary>Last hash</summary>
</key>
</schema>
</schemalist>
16 changes: 14 additions & 2 deletions src/module/gtkwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(self):
self.__init_gui()
self.__update_user_background_loop()
self.__connect_signals()
self.__last_hash = gsettings_get("last-hash").split("\n")

def __init_variables(self):
self.greeter_loaded = False
Expand Down Expand Up @@ -144,9 +145,16 @@ def msg_handler(self, message=""):

def login_handler(self):
if get("password-cache", True, "gtkwindow"):
username = lightdm.get_username()
new_hash = hashlib.sha512(
lightdm.get_password().encode("utf-8")).hexdigest()
writefile("{}-last-hash".format(lightdm.get_username()), new_hash)

new_last_hash = username+"="+new_hash+"\n"
for h in self.__last_hash:
if h.startswith(username+"="):
continue
new_last_hash += h + "\n"
gsettings_set("last-hash",new_last_hash.strip())
if get("username-cache", True, "gtkwindow"):
gsettings_set("last-username", lightdm.get_username())
gsettings_set("last-session", lightdm.get_session())
Expand Down Expand Up @@ -227,7 +235,11 @@ def __event_password_entry_changed(self, widget):
# get username from entry
username = self.o("ui_entry_username").get_text()
# read sha512sum from cache
last_hash = readfile("{}-last-hash".format(username))
last_hash = None
for h in self.__last_hash:
if h.startswith(username+"="):
last_hash = h[len(username)+1:]
break
# if hash and cache is equal run login event
if last_hash == hashlib.sha512(password.encode("utf-8")).hexdigest():
self.__event_login_button()
Expand Down
17 changes: 11 additions & 6 deletions src/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,26 @@ def get(variable, default=None, section="pardus"):
return False
return str(ret)

if get("debug", False, "pardus"):
def debug(msg):
log("[DEBUG] => {}\n".format(msg), type="debug")
else:
def debug(msg):
return


gsettings = Gio.Settings.new("tr.org.pardus.lightdm.greeter")

def gsettings_get(variable):
debug(variable)
debug(gsettings.get_string(variable))
return gsettings.get_string(variable)

def gsettings_set(variable, value):
debug(variable)
debug(value)
gsettings.set_string(variable,value)

if get("debug", False, "pardus"):
def debug(msg):
log("[DEBUG] => {}\n".format(msg), type="debug")
else:
def debug(msg):
return


def log(msg, type="log"):
Expand Down

0 comments on commit 976e565

Please sign in to comment.