#!/usr/bin/env python #auther = shaw #ver = 1.3 import startup account = {} acclist = [] #產生帳號信息字典 with open('accountlist.txt','r+') as acc: #accountlist.txt文件事先已被編寫好,一行用戶名,一行密碼 for i in acc.readlines(): acclist.append(i.strip('\n')) for i in range(0,len(acclist),2): name = acclist[i] passwd = acclist[i+1] account[name] = passwd i = 0 status = False #判斷主體 while i <= 2: name = raw_input('Please input your name:').strip() with open('lock.txt','r+') as acclock: # 判斷帳號是否被鎖定begin for f in acclock.readlines(): if name == f.strip('\n'): print '\033[31;2mSorry.you account has been locked.\033[0m' status = True break if status is True:break # 判斷帳號是否被鎖定end passwd = raw_input('Please input your passwd:').strip() if account.has_key(name) and account[name] == passwd: # 判斷用戶是否存在,以及此用戶密碼是否正確 print '### \033[32;2mLogin Succsss\033[0m.' break else: i = i + 1 print '### \033[33;2myour name or passwd wrong\033[0m...' continue # 用戶名密碼輸入錯誤3次,鎖定帳號 if i > 2: print '\033[31;2mSorry.you account has been locked.\033[0m' lock = file('lock.txt','a') lock.write('%s\n'% name) lock.close()