Python program to check if a password is correct

Python Methods and Functions

Here, given the password, our task is &make sure this password is valid or not. Here we are using the re module, which provides regular expressions, and re.search () is used to validate alphabets, numbers, or special characters.






Algorithm

 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 az. Step 4: At least one alphabet should be in Uppercase AZ. Step 5: At least 1 number or digit between 0-9. Step 6: At least 1 character from [_ or @ or $]. 



Sample Code

 # Python program to check valid password import re pas sw = input ("Enter Password :: & gt ; ") fl = 0 while True: if (len (passw) & lt; 8): fl = -1 break elif not re.search (" [az] ", passw): fl = -1 break elif not re.search ("[AZ]", passw): fl = -1 break elif not re.search ("[0-9]", passw): fl = -1 break elif not re.sear ch ("[_ @ $] ", 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") 



Output

 Ent er Password :: & gt; vbnA @ hj9 This Is Valid Password 







Get Solution for free from DataCamp guru