我有一个脚本,用于检查用户是否输入了与正确密码对应的有效用户名并授予访问权限。它还允许他们创建用户名和密码,并将其添加到词典中。但是,当我运行程序并创建新的用户名和密码时,会将它们添加到字典中,但不会永久保存,因为当再次运行该程序并打印字典时,我之前添加的值不再存在。
# creates a users dictionary
users = {
'Joe': 'juk725',
'Mat': 'axr3',
'Th3_j0k3r': 'bl4z3'
}
while username not in users and username != 'signup':
username = input("enter username(type signup to create an account): ")
if username == "signup" or username == "Signup":
create_username = input("enter a new username: ")
create_password = input("enter a new password: ")
if create_password in users:
create_password = input("password taken re-enter: ")
if create_username==create_password:
create_password=input("password cannot be the same as your username re-enter: ")
# then adds the new username to the users dictionary
if username == 'signup':
users[create_username] = create_password
else:
if username in users:
password = input("enter password: ")
if password in users:
print("access granted")