给定密码,我们的任务是检查该密码是否有效。在这里,我们使用提供正则表达式的re模块,并使用re.search()来检查字母,数字或特殊字符的有效性。
Step 1: first we take an alphanumeric string as a password. Step 2: first check that this string should minimum 8 characters. Step 3: the alphabets must be between a-z. Step 4: At least one alphabet should be in Uppercase A-Z. Step 5: At least 1 number or digit between 0-9. Step 6: At least 1 character from [_ or @ or $].
# Python program to check valid password import re passw = input("Enter Password ::>") fl = 0 while True: if (len(passw)<8): fl= -1 break elif not re.search("[a-z]", passw): fl = -1 break elif not re.search("[A-Z]", passw): fl = -1 break elif not re.search("[0-9]", passw): fl = -1 break elif not re.search("[_@$]", passw): fl = -1 break elif re.search("\s", passw): fl = -1 break else: fl = 0 print(" This Is Valid Password") break if fl ==-1: print("Not a Valid Password")
输出结果
Enter Password ::> vbnA@hj9 This Is Valid Password