欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python檢驗用戶輸入密碼的復(fù)雜度

 更新時間:2023年04月08日 11:52:10   作者:輕松學(xué)Python  
這篇文章主要介紹了Python檢驗用戶輸入密碼的復(fù)雜度,在用戶設(shè)置密碼的時候檢測輸入的密碼大小寫數(shù)字等,需要的朋友可以參考下

密碼強度檢測規(guī)則:

  • 至少包含一個數(shù)字
  • 至少包含一個大寫字母
  • 長度至少 8 位

主要知識點

  • while 循環(huán)
  • 推導(dǎo)式
  • 列表 any 函數(shù)
  • 命令行 input

代碼部分

密碼強度檢測

1、首先創(chuàng)建一個 python 文件

導(dǎo)入系統(tǒng)包

import platform

密碼強度檢測規(guī)則

至少包含一個數(shù)字至少包含一個大寫字母長度至少 8 位

每天打印一詞,激勵一下自己。

print("人生苦短,我用Python")

輸入密碼

while True:
    password = input("請輸入待檢測密碼: ")

列表推導(dǎo)式使用

print("數(shù)字檢測: ", [i.isdigit() for i in password])
print("大寫字母檢測: ", [i.isupper() for i in password])
print("密碼長度: ", len(password))

是否有數(shù)字, 推導(dǎo)式檢測。

hasNumber = any([i.isdigit() for i in password])

是否有大寫字母, 推導(dǎo)式檢測。

hasUpper = any([i.isupper() for i in password])

密碼檢測

if hasNumber and hasUpper and len(password) >= 8:
    print("密碼符合規(guī)則, 檢查通過")
    break
else:
    print("密碼校驗未通過, 請重新輸入")

2、運行結(jié)果

請輸入待檢測密碼: 123213
數(shù)字檢測:  [True, True, True, True, True, True]
大寫字母檢測:  [False, False, False, False, False, False]
密碼長度:  6
密碼校驗未通過, 請重新輸入
請輸入待檢測密碼: abc1234
數(shù)字檢測:  [False, False, False, True, True, True, True]
大寫字母檢測:  [False, False, False, False, False, False, False]
密碼長度:  7
密碼校驗未通過, 請重新輸入
請輸入待檢測密碼: Abc34567
數(shù)字檢測:  [False, False, False, True, True, True, True, True]
大寫字母檢測:  [True, False, False, False, False, False, False, False]
密碼長度:  8
密碼符合規(guī)則, 檢查通過

全部代碼

import platform
 
print("人生苦短,我用Python")
 
while True:
    password = input("請輸入待檢測密碼: ")
 
    print("數(shù)字檢測: ", [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("密碼符合規(guī)則, 檢查通過")
        break
    else:
        print("密碼校驗未通過, 請重新輸入")

到此這篇關(guān)于Python檢驗用戶輸入密碼的復(fù)雜度的文章就介紹到這了,更多相關(guān)Python檢驗密碼復(fù)雜度內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論