zoukankan      html  css  js  c++  java
  • 写一个注册的小程序,账号和密码都存在文件里面

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

    user_info = {} #存放所有的用户
    with open('users.txt') as f:
    for line in f:
    # niuhanyang,123456
    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+' ')
  • 相关阅读:
    如何让自己的app尽量不被系统杀死
    linux常用命令-权限管理命令
    linux常用命令-用户管理命令
    linux常用命令-文件处理命令
    npm命令
    新技术新框架新工具选型原则
    tomcat启动命令行中文乱码
    docker命令
    tinkpad e450c 进入 BIOS
    基于Java服务的前后端分离解决跨域问题
  • 原文地址:https://www.cnblogs.com/jiadan/p/8909268.html
Copyright © 2011-2022 走看看