Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.84 KB | None | 0 0
  1. import re
  2. loopstr = False
  3. regexstr = False
  4. def loopstrength(pword):
  5.     global loopstr
  6.     if len(pword) < 8:
  7.         print("First test: not strong - password is too short.")
  8.     elif not (any(c.isupper() for c in pword)):
  9.         print("First test: not strong - password must contain at least one uppercase character.")
  10.     elif not (any(c.islower() for c in pword)):
  11.         print("Second test: not strong - password must contain at least one lowercase character.")
  12.     elif not (any(c.isdigit() for c in pword)):
  13.         print("Second test: not strong - password must contain at least one digit.")
  14.     else:
  15.         print("First test: strong")
  16.         loopstr = True
  17.     return loopstr
  18.  
  19. def regexstrength(pword):
  20.     global regexstr
  21.     #At least 8 characters
  22.     regexlen = re.search(".{8,}", pword)
  23.     #At least one upper
  24.     regexup = re.search("[A-Z]+", pword)
  25.     #At least one lower
  26.     regexlo = re.search("[a-z]+", pword)
  27.     #At least one digit
  28.     regexdi = re.search("[0-9]+", pword)
  29.    
  30.     if regexlen is None:
  31.         print("Second test: not strong - password is too short.")
  32.     elif regexup is None:
  33.         print("Second test: not strong - password must contain at least one uppercase character.")
  34.     elif regexlo is None:
  35.         print("Second test: not strong - password must contain at least one lowercase character.")
  36.     elif regexdi is None:
  37.         print("Second test: not strong - password must contain at least one digit.")
  38.     else:
  39.         print("Second test: strong")
  40.         regexstr = True
  41.     return regexstr
  42.  
  43. while True:
  44.     usrpword = input("Enter a password (or 'quit' to exit): ")
  45.     if usrpword == 'quit':
  46.         print()
  47.         break
  48.     loopstrength(usrpword)
  49.     regexstrength(usrpword)
  50.     if loopstr == True and regexstr == True:
  51.         print()
  52.         break
  53.     print()
  54. print("Bye!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement