01 md5实现注册

  • md5实现注册
import  hashlib
def md5(data_string):
    obj = hashlib.md5()
	obj.update(pwd.encode('utf-8'))
	return obj.hexdigest() #密文
line = f'{user},{encrypt}\n'
#实现用户注册,密码加密
user = input('输入用户:')
pwd = input('输入密码')


with open ('db.txt','a',encoding='utf-8')as f:
    f.write(line)
  • md5封装成函数版本
def md5(data_string):
    obj = hashlib.md5()
    obj.update(data_string.encode('utf-8'))
    return obj.hexdigest()  # 密文



# 实现用户注册,密码加密
user = input('输入用户:')
pwd = input('输入密码')

encrypt = md5(pwd)
line = f'{user},{encrypt}\n'
with open('db.txt', 'a', encoding='utf-8') as f:
    f.write(line)

posted @ 2024-09-25 22:52  jhchena  阅读(4)  评论(0编辑  收藏  举报