Homework-Oneday-简单的用户登录

作业一:简单的用户登录

大概功能:

1、用户输入;2,、判断输入是否正确,正确登录,错误重新输入,输错三次锁定该用户

流程图:

 

代码:

import time

# user_name1 = 'like'
# password1 = 'l0123'

file = open('username.txt', 'w', encoding='utf-8')
file.write('like\nl0123')
file.close()
file_lock = open("username_lock.txt",'w',encoding='utf-8')
file_lock.close()

count = 0
while True:
    f = open('username.txt', 'r', encoding='utf-8')
    user_name1 = f.readline().strip()
    password1 = f.readline().strip()
    f.close()
    f1 = open("username_lock.txt", 'r', encoding='utf-8')
    lock_name = f1.readline().strip()
    f1.close()

    count += 1
    user_name = input('username:')
    password = input('password:')
    if user_name == lock_name:
        print('该用户已被锁定,请过3s后再试')
        time.sleep(10)
        f1 = open("username_lock.txt", 'w', encoding='utf-8')
        f1.close()
        continue
    if user_name == user_name1 and password == password1:
        print('Welcome user {username} login ...'.format(username=user_name))
        break
    else:
        print('Invalid username or password,Please resume load')
        print('用户输入次数为%d次,若输入错误次数达到3次,用户将被锁定' %(count))
    if count == 3:
        print('You have tried too  mang times ...,用户已被锁定')
        f_lock = open("username_lock.txt",'a',encoding='utf-8')
        f_lock.write(user_name)
        f_lock.close()
        continue

 

posted @ 2018-03-21 15:02  litwit  阅读(153)  评论(0)    收藏  举报