簡體   English   中英

如何根據用戶輸入檢查密碼的有效性

[英]How To check the validity of password according to input by users

檢查用戶密碼輸入的有效性。

以下是檢查密碼的標准:

  1. az之間至少1個字母。
  2. 0-9之間至少1個數字
  3. AZ之間至少2個字母
  4. $#@,中至少2個字符。 等等
  5. 交易密碼的最小長度:6
  6. 交易密碼的最大長度:12

這個問題的答案無法解決問題

我試過了但是沒用

N = [1,2,3,4,5,6,7,8,9,0]
A = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
S = ['!','@','#','$','%','~','`','^','&','*','(',')','_','+','=','-']

pasw = input('Password: ')
if any((word in pasw for word in N,A,S)):
  print ('OK')
else:
   print ('TRY LATER')

最好的方法是使用建議的正則表達式,但是如果您不知道是什么,那就是一個全新的世界。 我建議你閱讀。

但是使用您理解的代碼可以做到:

pasw='PAssword1!!'

S = ['!','@','#','$','%','~','`','^','&','*','(',')','_','+','=','-']
upper,lower,number,special = 0,0,0,0

for n in pasw:
    if n.islower():
        lower=1
    if n.isnumeric():
        number=1
    if n.isupper():
        upper+=1
    if n in S:
        special+=1

if len(pasw) >= 6 and len(pasw) <= 12 and lower > 0 and number > 0 and special > 1 and upper > 1:
    print('OK')
else:
    print('TRY LATER')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM