用户登陆接口(BATE)

#用户输入用户名密码,若是在锁定文件中,则告知用户名已被锁定。
#如用户不在锁定文件中,匹配用户名和密码,若是验证成功打印欢迎介面
#若是匹配不成功,让用户从新输入,用户有三次机会,超过3次退出程序
#若是用户最后输入的用户名在系统用户文件中,则将其写入到锁定文件,反之则不写入锁定文件。

# 文件account.txt内容以下:
# Jacky   1234
# sky     3356
# Yvone   5566

#account_lock.txt为空

cmd = input('''
    1:登陆系统
    2:即出系统
请选择:
''')

if cmd.isdigit() and int(cmd) == 2:
    exit()
elif cmd.isdigit() and int(cmd) == 1:
    pass
else:
    print('您输入有误!')
    exit()

i = 0
j = 0
while i < 3:
    user_input = input('Please input your username:')
    passwd_input = input('Please input your password:')
    list_lock = open('account_lock.txt', 'r+')
    lock_user = list_lock.readlines()
    for line in lock_user:
        lines = line.strip('\n')
        if lines == user_input:
            print('Username %s has been locked!' % user_input)
            exit()
    else:
        pass

    list_user = open('account.txt', 'r')
    user_info = list_user.readlines()
    for line in user_info:
        (username, password) = line.strip('\n').split()
        if username == user_input and password ==  passwd_input:
            print('''\033[1;32m
*************************************************
*                  WELCOME                      *
*************************************************
            \033[0m''')
            j = 3
            break
    if j < 2:
        j += 1
        print('\033[1;31m\nWrong username or password \033[0m')
        continue
    else:
        # 判断用户输入的用户名是否在系统的用户列表中,若是存在将用户名锁定,若是不存在则不加入锁定文件中。
        for i in user_info:
            if j != 3 and user_input in i.strip('\n').split():
                list_lock.write(user_input + '\n')
        i = 3

list_lock.close()
list_user.close()



print('contin')
相关文章
相关标签/搜索