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 
' % username)
        lock_file.close()
        user_pass.close()
        exit()
原文地址:https://www.cnblogs.com/ne-zha/p/7143553.html