1. 程式人生 > >python文件調用小練習——用戶登錄及鎖定

python文件調用小練習——用戶登錄及鎖定

password 三次 存儲 inpu 功能 utf 用戶登錄 odi body

 1 # -*- coding: utf-8 -*-
 2 ‘‘‘
 3  --------------------------------------------
 4 已有功能:輸入用戶名密碼;認證成功後顯示歡迎信息;輸錯三次後永久鎖定
 5 待以後添加:定時解鎖;使用數據庫等大量存儲用戶並調用
 6  --------------------------------------------
 7  ‘‘‘
 8 username = AAA
 9 password = aaa
10 
11 def userLock():
12     try_times = 0
13     while
try_times < 3: 14 usernameInput = input(用戶名:) 15 if usernameInput == username: 16 with open(userLock,r,encoding=utf-8) as userLock_file: 17 if usernameInput in userLock_file: 18 print("用戶%s已被鎖定,請聯系客服(客服電話:10086)!" % usernameInput)
19 return 0 20 else: 21 times = 0 22 while times < 3: 23 passwordInput = input(密 碼:) 24 if passwordInput == password: 25 print("%s,感謝您的登錄!\n\t歡迎!
" % username) 26 return 0 27 else: 28 print("密碼輸入錯誤!請重新輸入!") 29 times += 1 30 else: 31 with open(userLock,r+,encoding=utf-8) as fileUserLock: 32 fileUserLock.write(usernameInput) 33 print("用戶已鎖定,請聯系客服(客服電話:10086)!") 34 return 0 35 else: 36 print("無效的用戶名!") 37 try_times += 1 38 39 40 userLock()

python文件調用小練習——用戶登錄及鎖定