日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

用户登录验证(新增帐号错误重试)

發布時間:2024/4/17 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 用户登录验证(新增帐号错误重试) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
#!/usr/bin/env python3 # -*- coding:utf-8 -*- # # Author: Payne Zheng <zzuai520@live.com> # Date: 2018-04-11 10:41:15 # Location: DongGuang # Desc: User login authentication # def CheckUserStatus(user):"""檢查帳號是否在鎖定文件中"""try:with open(user_lock_file, 'r', encoding="utf-8") as f1:for line in lines:if line.strip() == user:return "lock"except FileNotFoundError:pass"""設定變量""" user_lock_file = "lock.txt" user_retry_num = pass_retry_num = 3 user_pass_dict = {"jack": "abc123","jushua": "123abc","payne": "a1b2c3" }"""接收用戶輸入""" input_user = input("\033[34mPlease enter your account number:\033[0m") input_pass = input("\033[34mPlease enter your password:\033[0m")"""檢查用戶帳號狀態,如在鎖定帳號文件則報錯退出""" if CheckUserStatus(input_user) == "lock":print("""\033[31mError! %s user has been locked,""""""unable to login, please contact customer service phone 10086.\033[0m""")exit()"""驗證帳號密碼""" while True:# 帳號密碼正確,打印歡迎信息if input_user in user_pass_dict and user_pass_dict.get(input_user) == input_pass:print("\033[32mSuccessful login, welcome <%s>\033[0m" % input_user)breakelse:# 帳號錯誤,提示帳號錯誤信息if input_user not in user_pass_dict:print("\033[33mSrror! the user <%s> in not exist" % input_user)input_user = input("please re-enter (you still have %s retry opportunity): \033[0m""" % (user_retry_num - 1))user_retry_num -= 1if user_retry_num == 1:print("\033[31mSorry, you enterd accounts <%s> not exist exceeds the number of retries" % input_user)break# 密碼錯誤,提示密碼錯誤信息else:print("\033[33mSrror! the password entered is not correct")input_pass = input("please re-enter (you still have %s retry opportunity): \033[0m"% (pass_retry_num-1))pass_retry_num -= 1# 重輸密碼三次后打印帳號鎖定信息,并將帳號存入鎖定文件進行鎖定if pass_retry_num == 1:print("""\033[31mSorry, the accounts <%s> password input error exceeds the number of retries""""""the account has been locked!\033[0m""" % input_user)with open(user_lock_file, 'a', encoding="utf-8") as f:f.writelines(input_user + "\n")break

?

轉載于:https://www.cnblogs.com/PAYNE1Z/p/8795772.html

總結

以上是生活随笔為你收集整理的用户登录验证(新增帐号错误重试)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。