校驗密碼是否合法的小程序——密碼里面必須包含,大寫字母、小寫字母和數字



一、校驗密碼是否合法的程序。
輸入一個密碼
1、長度5-10位
2、密碼里面必須包含,大寫字母、小寫字母和數字
# http://www.nnzhp.cn/archives/160 取交集的這種方式可以實現
3、最多輸入5次

for i in range(5):
passwd = input('passwd:').strip()
if passwd!='':
if len(passwd)>4 and len(passwd)<11:
num_count = 0 # 數字出現的次數
lower_count = 0 # 小寫字母出現的次數
upper_count = 0 # 大寫字母出現的次數
for p in passwd:
if p.isdigit():
num_count+=1
elif p.islower():
lower_count+=1
elif p.isupper():
upper_count+=1
if num_count>0 and lower_count>0 and upper_count>0:
print('密碼校驗通過')
else:
print('密碼不合法')
else:
print('密碼最少5位,最長10')
else:
print('不能為空')


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM