Advertisement
DeaD_EyE

password validation without regex

Apr 14th, 2020
462
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. # Answer to http://dpaste.com/37ZVD3M
  2.  
  3.  
  4. import string
  5.  
  6.  
  7. def validate(password):
  8.     """
  9.    Its a general password validation question
  10.    - one uppercase
  11.    - one lowecase
  12.    - special charater .,/
  13.    - posivitve integer
  14.    """
  15.     # Minimum one uppercase
  16.     if not any(c.isupper() for c in password):
  17.         return False
  18.    
  19.     # Minimum one lowercase
  20.     if not any(c.islower() for c in password):
  21.         return False
  22.    
  23.     # . or , or / are required
  24.     if not any(c in ".,/" for c in password):
  25.         return False
  26.    
  27.     # Minimum one digit in password
  28.     if not any(c in string.digits for c in password):
  29.         return False
  30.    
  31.     # No negative integers in str
  32.     if any(
  33.         last == "-" and current.isdigit()
  34.         for (last, current)
  35.         in zip(*[iter(password)] * 2)
  36.     ):
  37.         return False
  38.    
  39.     return True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement