-
Notifications
You must be signed in to change notification settings - Fork 0
/
password.py
63 lines (52 loc) · 1.79 KB
/
password.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
def password(file):
"""
This function will generate and print two 2 worded password.
The user will provide the word text file to be read by the function.
@param: None
@return: None
"""
import random
# Declare variable.
word_list = list()
option = ""
with open(file, 'r') as f:
# Give user loading status feedback.
print("Loading ...")
print('...\n...')
# Move words with length up to 3 into ls.
for line in f:
for word in line.split():
if len(word) >= 3 and word.isalpha():
word_list.append(word)
print('...')
print("Program loaded successfully!\n")
while True:
# Quit if the user enters 'q'.
if option.lower() == 'q':
break
# If return is hit instead, generate the password.
elif option == "":
while True:
# Generate 2 random words from word list.
word1 = random.choice(word_list)
word2 = random.choice(word_list)
# if the numbers are the same or their lengths combined
# is not between 8 and 10, continue, else concatenate.
if word1 == word2 or not 8 <= len(word1 + word2) <= 10:
continue
else:
pas = word1.capitalize() + word2.capitalize()
print(f'Password: {pas}')
print()
break
option = input("Hit return to generate a new password or enter 'q' to end: ")
def main():
# Request input from user.
file = input("\nEnter word file name: ")
try:
# Generate password.
password(file)
except:
print("Enter valid file name!")
if __name__ == '__main__':
main()