import sys
import hashlib
user = {}
#菜单界面
def menu():
print("\t\t 1.用户注册")
print("\t\t 2.用户登录")
print("\t\t 3.退出系统")
a = input('请选择你要的功能')
return a
#密码加密
def password_md5(password):
md5 = hashlib.md5(password.encode("utf-8"))
# 盐值混淆
md5.update('!@@@@&%hhh'.encode("utf-8"))
return md5.hexdigest()
#用户注册
def register():
print('用户注册')
username = input("请输入你的用户名称:")
password = input("请输入你的用户密码(密码大于3位):")
if username == None or username.strip() == " ":
print("用户名不能为空")
return
if password == None or password.strip() == " " or len(password) < 3:
print("密码长度不能小于3位")
return
for i in user:
if username == i:
print('请重新输入,你输入的账户名重复')
return
user[username] = username
user[username+'的'+'password'] = password_md5(password)
#用户登陆
def login():
print('用户登陆')
username = input("请输入你的用户名称:")
password = input("请输入你的用户密码:")
if username == user.get(username,'用户不存在') and password_md5(password) == user.get(username + '的' + 'password','密码错误'):
print('用户登陆成功')
else:
print('6')
print(username)
print(user.get(username,'用户不存在'))
print(password_md5(password))
print(user.get(username + '的' + password_md5(password),'密码错误'))
while True:
choice = menu()
if choice == '1':
register()
elif choice == '2':
login()
elif choice == '3':
sys.exit()
这个代码将账户密码存储再字典中,且再代码运行关闭后,字典中存储的账户密码都将会消失