python日记(一)简单的密码登录

# readme:
#     blogger address:www.cnblogs.com/ne-zha
#     ne_zha
#     要求:
#     编写登陆接口
#     1.输入用户名密码
#     2.登录成功显示欢迎信息
#     3.输错三次锁定


lock_file=open('file_lock.txt','r')
user_pass=open('username_file.txt','r')

cmd =int(input('''
登录系统输入1
退出系统输入2
请输入操作:
 '''))
if cmd ==2:
    exit()
elif cmd ==1:
    username = input("please input your user...")
    for i in range(3):
        for i in lock_file.readlines():
            i = i.split()
            if username in i[0]:
                print('对不起 %s 已锁定' % username)
                exit()
    match = False
    for j in user_pass.readlines():
        user,passwd =j.split()
        if username ==user:
            password =input("please input the passwd")
            if password ==passwd:
                print("登录成功!")
                match = True
                break
            elif password !=passwd:
                for n in range(2):
                    password =input("密码错误,请重新输入!")
                    if password ==passwd:
                        print("登录成功!")
                        match = True
                        break
    if username !=user:
        print("用户名不存在!")
        exit()
    if match ==False:
        print("三次输入错误,账户以被锁定!")
        lock_file.write('%s \n' % username)
        lock_file.close()
        user_pass.close()
        exit()

 

转载于:https://www.cnblogs.com/ne-zha/p/7143553.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值