forked from synackray/flask-password
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword_generator.py
executable file
·32 lines (29 loc) · 1.15 KB
/
password_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
import random
DICT_PATH = "dictionaries/"
DICT_FILES = {"en": "american-english.txt", "it": "italian.txt"}
SYMBOLS = "~!@#$%^&*()_-+="
def generate_password(
language="en", spaces="0", symbol="1", uppercase="1"):
# Handle users passing non-existent languages
if language in DICT_FILES:
dict_file = DICT_PATH + DICT_FILES[language]
else:
dict_file = DICT_PATH + DICT_FILES["en"]
with open(dict_file, "r") as file:
# Remove new lines
words = [word.strip() for word in file]
# Remove any words with apostrophes
words = [word for word in words if "'" not in word]
password = ' '.join(random.choice(words) for i in range(4))
# Process complexity rules
if spaces == "0":
password = password.title()
password = "".join(["" if c == " " else c for c in password])
if symbol == "1":
password += random.choice(SYMBOLS)
if uppercase == "1":
password = password[0].upper() + password[1:]
return password
if __name__ == "__main__":
print("Your randomly generated password is:", generate_password())