Advertisement
snozzy

safe_password.py

Feb 24th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. import random
  2. import string
  3. import re
  4.  
  5.  
  6. def validate_password(password):
  7.     with open("ordlista_sv.txt", "r") as wl:
  8.         wordlist = wl.readlines()
  9.     wl.close()
  10.     wordlist = [x[:-1] for x in wordlist]
  11.  
  12.     if len(password) >= 8:
  13.         if password not in wordlist:
  14.             if re.search('[a-z]', password) and re.search('[A-Z]', password) \
  15.                     and re.search('[0-9]', password) and re.search(r"[!\"#$%&'()*+,\-./:;<=>?@\[\]^_`{|}~]", password):
  16.                 print(password, "is valid")
  17.                 return True
  18.  
  19.             else:
  20.                 print(password, "is invalid")
  21.                 return False
  22.  
  23.  
  24. def generate():
  25.     valid = False
  26.     while not valid:
  27.         password = string.ascii_letters + string.digits + string.punctuation
  28.         password = "".join(random.choice(password) for i in range(10))
  29.         digits = 0
  30.         valid = validate_password(password)
  31.         if valid:
  32.             return password
  33.  
  34.  
  35. generate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement