Я делаю страницу забытого пароля для своей программы python. Когда я нажимаю кнопку «Готово» на этой странице, он должен изменить пароль моего файла «users. json» для введенного имени пользователя, но вместо этого ничего не происходит. Я попытался изучить эту проблему, но ничего не нашел. Как я могу этого добиться?
Вот мой python код для этой страницы: -
class ForgotPasswordScreen2(Screen):
def reset_pwd(self, lastpwd, newpwd, confirmpwd, usernm):
npwd = newpwd
cnfpwd = confirmpwd
lstpwd = lastpwd
with open("Emotional Quoter/users.json", 'r') as file:
oldpassword = file.read()
if len(get_close_matches(lstpwd, [oldpassword])) > 0 :
if npwd == cnfpwd:
with open("Emotional Quoter/users.json", 'w+') as file:
users = json.load(file)
if len(npwd) < 8:
self.ids.wrong_pass.text = "Make sure your password is at lest 8 letters"
elif re.search('[0-9]', npwd) is None:
self.ids.wrong_pass.text = "Make sure your password has a number in it"
elif re.search('[A-Z]', npwd) is None:
self.ids.wrong_pass.text = "Make sure your password has a capital letter in it"
else:
users[usernm] = {'username': usernm, 'password': cnfpwd,
'created': datetime.now().strftime("%Y-%m-%d %H-%M-%S")}
with open("Emotional Quoter/users.json", 'w') as file:
json.dump(users, file)
self.manager.current = "forgot_screen_success"
else:
self.ids.wrong_pass = "Invalid Pass"
Вот мой код kivy: -
<ForgotPasswordScreen2>:
GridLayout:
cols:1
GridLayout:
cols: 2
rows: 4
Label:
font_size: "30sp"
text: "FORGOT PASSWORD"
bold: True
GridLayout:
cols: 2
rows: 4
Label:
text: "User name :"
TextInput:
id: usernm
Label:
text: "Enter last password :"
TextInput:
id: lastpwd
Label:
text: "New Password : "
TextInput:
id: newpwd
Label:
text: "Confirm New Password :"
TextInput:
id: confirmpwd
GridLayout:
rows: 2
cols: 1
Label:
id: wrong_pass
text: ""
Button:
text: "DONE"
on_press: root.reset_pwd(root.ids.usernm.text,root.ids.lastpwd.text, root.ids.newpwd.text, root.ids.confirmpwd.text)
пожалуйста помоги мне.