Advertisement
elena1234

password validation in Python with RegEx

Feb 10th, 2022 (edited)
1,493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. import re
  2. # At least 8 char long
  3. # Contain any sort letters, numbers and $%#@
  4. # Has to end with number
  5.  
  6. pattern = re.compile(r"(^[\w$%#@]{7,}[\d]+$)")
  7. passwords = ["edgde4gtg%@3", "ffefefe%%%4", "$5swdwd#fe63", "---fefe---", "12er5"]
  8.  
  9. print("Valid passwords are:")
  10. for password in passwords:
  11.     if pattern.match(password):
  12.         print(password) # edgde4gtg%@3, ffefefe%%%4, $5swdwd#fe63
  13.        
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement