1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| import hashlib
def md5(arg): md5_pwd = hashlib.md5(bytes('abd',encoding='utf-8')) md5_pwd.update(bytes(arg,encoding='utf-8')) return md5_pwd.hexdigest() def log(user,pwd): with open('db','r',encoding='utf-8') as f: for line in f: u,p=line.strip().split('|') if u ==user and p == md5(pwd): return True def register(user,pwd): with open('db','a',encoding='utf-8') as f: temp = user+'|'+md5(pwd) f.write(temp)
i=input('1表示登陆,2表示注册:') if i=='2': user = input('用户名:') pwd =input('密码:') register(user,pwd) elif i=='1': user = user = input('用户名:') pwd =input('密码:') r=log(user,pwd) if r ==True: print('登陆成功') else: print('登陆失败') else: print('系统不存在此功能模块')
|