写一个注册的小程序,账号和密码都存在文件里面

2、写一个注册的程序,账号和密码都存在文件里面。
choice = input('请输入你的选择:1,注册2、删除用户3、登录')
注册
输入
账号
密码
密码确认
#需要校验用户是否存在,两次输入的密码,是否一致,为空的情况
账号和密码都存在文件里面
删除
输入一个用户名
需要校验用户是否存在
登录
输入账号密码登录

user_info = {} #存放所有的用户
with open('users.txt') as f:
for line in f:
# niuhanyang,123456\n
line = line.strip()
temp = line.split(',')
username = temp[0]
pwd = temp[1]
user_info[username]=pwd
for i in range(3):
choice = input('请输入你的选择'
'1、登录 2、注册 3、删除').strip()
if choice=='1':
username = input('username:').strip()
pwd = input('pwd:').strip()
if username and pwd:
if username in user_info:
if user_info.get(username)==pwd:
print('登录成功')
else:
print('账号密码错误!')
else:
print("user not found!")
else:
print('账号密码不能为空!')
elif choice=='2':
username = input('username:').strip()
pwd = input('pwd:').strip()
cpwd = input('cpwd:').strip()
if username and pwd and cpwd:
if username in user_info:
print('该用户已经被注册!')
else:
if pwd==cpwd:
user_info[username]=pwd
print('恭喜,注册成功!')
else:
print('两次输入的密码不一致!')
else:
print('不能为空!')
elif choice=='3':
username = input('username:').strip()
if username:
if username in user_info:
user_info.pop(username)
print('删除成功!')
else:
print('不能为空!')
else:
print("输入有误,请重新输入")
else:
with open('users.txt','w') as fw:
for uname,pwd in user_info.items():
fw.write(uname+','+pwd+'\n')

转载于:https://www.cnblogs.com/jiadan/p/8909268.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值