用Python檢測用戶輸入密碼的復雜度,灰常簡單!
密碼強度檢測規則:
- 至少包含一個數字
- 至少包含一個大寫字母
- 長度至少 8 位
主要知識點
- while 回圈
- 推導式
- 串列 any 函式
- 命令列 input
代碼部分
密碼強度檢測
1、創建 python 檔案
密碼強度檢測規則
1 至少包含一個數字
2 至少包含一個大寫字母
3 長度至少 8 位
# 匯入系統包 import platform ''' Python學習交流群:279199867 進群后可領取海量:Python視頻教程、100本Python電子書、基礎、爬蟲、資料分析、web開發、機器學習、人工智能、面試題、Python學習路線圖、問題解答~ ''' print("Hello,秀兒") while True: password = input("請輸入待檢測密碼: ") # 推導式使用 print("數字檢測: ", [i.isdigit() for i in password]) print("大寫字母檢測: ", [i.isupper() for i in password]) print("密碼長度: ", len(password)) # 是否有數字, 推導式檢測 hasNumber = any([i.isdigit() for i in password]) # 是否有大寫字母, 推導式檢測 hasUpper = any([i.isupper() for i in password]) if hasNumber and hasUpper and len(password) >= 8: print("密碼符合規則, 檢查通過") break else: print("密碼校驗未通過, 請重新輸入") print("版本", platform.python_version())
2、運行結果

轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/499031.html
標籤:Python
上一篇:字串(str、bytes)
