import hashlib def md5(arg):#這是加密函數 md5_pwd = hashlib.md5(bytes('meac',encoding='utf-8')) md5_pwd.update(bytes(arg,encoding='utf-8')) return md5_pwd.h... ...
import hashlib def md5(arg):#這是加密函數 md5_pwd = hashlib.md5(bytes('meac',encoding='utf-8')) md5_pwd.update(bytes(arg,encoding='utf-8')) return md5_pwd.hexdigest()#返回加密的數據 def log(user,pwd): try: with open('login','r',encoding='utf-8') as f: for line in f: u,p=line.strip().split('|') if u ==user and p == md5(pwd):#登陸的時候驗證用戶名以及加密的密碼跟之前保存的是否一樣 return True return False except: return False def register(user,pwd):#註冊的時候把用戶名和加密的密碼寫進文件,保存起來 with open('login','a',encoding='utf-8') as f: temp = user+'|'+md5(pwd) f.write(temp) while 1: m=input('請您輸入序號:1。代表登錄,2.代表註冊') if m=='1': user=input('請輸入登錄賬號:') pasw=input('請輸入登錄賬號密碼:') if log(user,pasw) ==False: print('登錄失敗,系統推出') break else: print('登錄成功') elif m=='2': user = input('請輸入註冊賬號:') pasw = input('請輸入註冊賬號密碼:') register(user,pasw) print('註冊成功') else: print('不存在你要的功能') break