import hashlib
md5=hashlib.md5()
sha1=hashlib.sha1()
name=[]
password=[]
user={}
dict(user)
#用戶注冊
while True:
choice = input('1:用戶注冊\t2:驗證登錄\t')
choice = int(choice)
while choice==1:
print('----用戶注冊----'.center(40))
name_=input('(用戶名由數字、字母、符號組成)\n請輸入要注冊的用戶名:')
name.append(name_)
password_=input('(密碼由數字、字母、符號組成)\n請設置用戶密碼')
print(password_)
print('通過md5加密中...'.center(40))
md5.update(password_.encode('utf-8'))
print(md5.hexdigest())
password.append(md5.hexdigest())
#將用戶名和密碼保存到字典
choice1=input('注冊成功!\b\n輸入1返回\t輸入2繼續注冊\t')
choice1=int(choice1)
if choice1==1:
break
else:
continue
user = dict(zip(name, password))
print(user)
#驗證登錄
while choice==2:
print('----用戶登入----'.center(40))
_name=input('用戶名:')
if _name in user.keys():
_password = input('密碼:')
print(_password)
print('md5加密中...'.center(40))
md5.update(_password.encode('utf-8'))
print(md5.hexdigest())
if md5.hexdigest()==user[_name]:
print('登錄成功!\n歡迎使用!'.center(40))
break
else:
print('密碼錯誤!'.center(40))
continue
else:
print('用戶名不存在!'.center(40))
continue