Advertisement
Guest User

pwd_generator

a guest
Jul 6th, 2016
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. import random, re
  2.  
  3. a = 0
  4. password = ''
  5.  
  6. while a < 8:
  7.     if random.randint(0, 61) < 10:
  8.         password += chr(random.randint(48, 57))
  9.     elif 10<random.randint(0, 61)<36:
  10.         password += chr(random.randint(65, 90))
  11.     else:
  12.         password += chr(random.randint(97, 122))
  13.     a += 1
  14.  
  15. print(password)
  16.  
  17. ## OUTPUT: t1fGf4Ha
  18.  
  19. #divide the 8 character to 2 part. first 3 and last 5.
  20.  
  21. print(password[:3])
  22. ## OUTPUT: t1f
  23.  
  24. print(password[3:])
  25. ## OUTPUT: Gf4Ha
  26.  
  27. #make sure in the first part all 3 kinds of character are being used
  28.  
  29. def password_check(password):
  30.     # calculating the length
  31.     length_error = len(password) < 8
  32.  
  33.     # searching for digits
  34.     digit_error = re.search(r"\d", password) is None
  35.  
  36.     # searching for uppercase
  37.     uppercase_error = re.search(r"[A-Z]", password) is None
  38.  
  39.     # searching for lowercase
  40.     lowercase_error = re.search(r"[a-z]", password) is None
  41.  
  42.      # overall result
  43.     password_ok = not ( length_error or digit_error or uppercase_error or lowercase_error)
  44.  
  45.     return password_ok
  46.    
  47. password_check(password)
  48.  
  49. #suffle
  50.  
  51. if password_check(password) == True:
  52.     new_pwd = ''.join(random.sample(password,len(password)))
  53.     print new_pwd
  54.    
  55.    
  56. # OUTPUT: G1ft4afH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement