Advertisement
lukajda33

Oython password checker

Nov 14th, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.20 KB | None | 0 0
  1. def passwordIsOk (code):
  2.     special_char = "$#%*"
  3.     okLower = False
  4.     okNumber = False
  5.     okUpper = False
  6.     okSpecial = False
  7.  
  8.     if len(code) < 10:
  9.         print("Short password")
  10.         return False
  11.    
  12.     if " " in code:
  13.         print("Space in password.")
  14.         return False
  15.  
  16.     for letter in code:
  17.         if letter.isupper():
  18.             okUpper = True
  19.         elif letter.islower():
  20.             okLower = True
  21.         elif letter.isdigit():
  22.             okNumber = True
  23.         elif letter in special_char:
  24.             okSpecial = True
  25.            
  26.     if not okLower:
  27.         print("No lowercase letter.")
  28.     if not okNumber:
  29.         print("No digit.")
  30.     if not okUpper:
  31.         print("No uppercase letter.")
  32.     if not okSpecial:
  33.         print("No special character.")
  34.    
  35.     return okUpper and okLower and okNumber and okSpecial
  36.  
  37. while True:
  38.     userPassword = input("Please enter a password: ")
  39.     valid = passwordIsOk( userPassword )
  40.     if not valid:
  41.         print ( "This password is invalid, please try again" )
  42.         continue
  43.     else:
  44.         print ("Your password is", userPassword)
  45.         break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement