#coding:gbk__author__ = 'zhb'import sys,os,getpassos.system('cls')i=0while i <3: name=raw_input("請輸入用戶名:") lock_file=open(r'account_lock.txt','r') for ...
#coding:gbk
#author:zhb
import getpass,os,sys
os.system('cls')
i=0
while i<3:
name=raw_input('輸入用戶名:')
lock_file=open(r'account_lock.txt','r+')
for lock_line in lock_file.readlines():
lock_line=lock_line.strip('\n')
if lock_line==name:
sys.exit('用戶 %s 存在於被鎖定文件中!請重新登錄運維平臺!再見!' %name)
else:
pass
user_file=open(r'account.txt','r')
for user_line in user_file.readlines():
(user,password)=user_line.strip('\n').split()
if user==name:
j=0
while j<3:
passwd=getpass.getpass("input password:")
if password==passwd:
sys.exit("熱烈歡迎 %s 進入運維平臺" %name)
else:
if j!=2:
print("密碼輸入錯誤, 用戶 %s 還有 %d 次輸入機會" %(name,2-j))
j+=1
else:#密碼輸錯3次,鎖定並追加到account_lock.txt里
lock_file.write(name+'\n')
sys.exit("由於連續輸入密碼3次錯誤, 該賬號 %s 已被鎖定,請聯繫IT人員進行解綁" %name)
else:
pass
i+=1
else:
sys.exit('系統中不存在用戶 %s ,請重新登錄' %name)