python 简单的 用户注册登陆

注册功能

#实现注册功能

while 1:
	dic={}
	with open("regit.txt", mode='r+', encoding="utf-8")as fp:
		res = fp.read()
	#username 注册的用户名
	username=input("请输入您的用户名:").strip()

	#判断用户名是否重复
	temp="'username': '{}',".format(username)
	if temp in res:
		print("用户名重复")
		continue
	#用户注册密码
	while 1:
		password = input("请您的输入密码:")
		# 用户确认密码:
		password2 = input("请再次您的确认密码:")
		if password==password2:
			print("恭喜您,账户注册成功")
			break
		else:
			print("对不起,两次密码不一致,请重新输入")
	dic["username"]=username
	dic["password"]=password

	with open("regit.txt",mode='a+',encoding="utf-8")as fp:
		fp.write("{}\n".format(dic))
#添加推出功能
#if username.upper()=="Q":break

#实现登陆功能

登陆模块

hmd=[]
while 1:

	#username:
	username=input("请输入您的账户").strip()
	with open("regit.txt", mode='r', encoding="utf-8")as fp:
		res = fp.read()
	temp = "'username': '{}',".format(username)

	if temp not in res:
		print("用户名不存在")
		continue
	with open("hmd.txt", mode='r', encoding="utf-8")as fp:
		res = fp.read()
	temp = "['{}']".format(username)

	if temp  in res:
		print("您的账户异常,已被冻结,请联系管理员")
		break
	password=input("请输入您的密码")
	with open("regit.txt", mode='r', encoding="utf-8")as fp:
		res = fp.read()
	temp = "'username': '{}', 'password': '{}'".format(username,password)
	print(res)
	if temp  in res:
		break
		print("恭喜您登陆成功")
	else:
		i=2
		while i>0:

			print("你输入的密码错误请重新输入")
			password = input("请输入您的密码")
			temp = "'username': '{}', 'password': '{}'".format(username, password)
			if temp in res:
				break
				print("恭喜您登陆成功")

			i -= 1
		hmd.append(username)
		with open("hmd.txt",mode="a",encoding="utf-8")as fp:
			fp.write("{}\n".format(hmd))
		print("你输入的密码错误3次,请联系管理员!")
		break
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值