python 3.5 用户登录验证和输入三次密码锁定用户
1 #!/usr/bin/env python 2 #encoding: utf-8 3 #登录程序,输入用户和密码输出欢迎信息,输入错误三次锁定用户,不让登录 4 import sys 5 print (''' 6 欢迎登陆我们的系统 7 ''') 8 9 pass_file = open('passwd.txt','r') 10 clok_file = open('clok.txt','r') 11 12 name_list = [] 13 clok_list = [] 14 name_dict = {} 15 for i in pass_file: 16 name, passwd = i.strip('\n').split(':') 17 name_list.append(name) 18 name_dict[name] = passwd 19 pass_file.close() 20 for i in clok_file: 21 clok_list.append(i.strip('\n')) 22 clok_file.close() 23 #print (clok_list) 24 25 num = 1 26 name = input('please input your name:') 27 if name in clok_list: 28 print ('your name is clok ,peasle system admin') 29 sys.exit() 30 if name in name_dict: 31 while num <=3: 32 passwd = input('please input your passwd:') 33 if passwd == name_dict[name]: 34 print ('welcome to wo system') 35 break 36 else: 37 print ('pass error') 38 num += 1 39 else: 40 print ('user no system') 41 42 if num > 3: 43 print ('your name is clok ,peasle system admin') 44 f = open('clok.txt','a') 45 f.write(name +'\n') 46 f.close()
passwd.txt 文件按格式
用户名:密码
用户名2:密码
clok.txt 文件格式
用户名1
用户名2