编写登陆接口
编写登陆接口
- 输入用户名密码
- 认证成功后显示欢迎信息
- 输错三次后锁定
1 # -*- coding:utf-8 -*- 2 # !/usr/bin/env python 3 # Author:dc0012 4 5 import sys 6 count = 0 7 while True: 8 flag_of_lock = 0 9 login_username = input('Please input your username:') 10 with open('/home/dc/lock_account', 'r') as f_lock: 11 for l in f_lock: 12 if login_username == l.strip(): 13 print('Sorry,This account was locked,Please try later') 14 flag_of_lock = 1 15 break 16 if flag_of_lock == 1: 17 continue 18 19 with open('/home/dc/account', 'r') as account, \ 20 open('/home/dc/lock_account', 'a') as add_lock_account: 21 for i in account: 22 username, password = i.split() 23 if username == login_username: 24 while count < 3: 25 login_password = input('Password:') 26 if password == login_password: 27 print('Welcome %s login!' % username) 28 sys.exit() 29 else: 30 print('incorrect password') 31 count += 1 32 print('Sorry,You try too many times,This account will be locked!') 33 add_lock_account.write(username) 34 sys.exit() 35 print('No such this username,Please try again....')
readme:
/home/dc/account文件存放用户名密码,每一行是一个账户,以空格隔开用户名和密码。
/home/dc/lock_account文件存放被锁定的用户名,一行为一个用户。