-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword_generator.py
More file actions
104 lines (104 loc) · 5.64 KB
/
Copy pathpassword_generator.py
File metadata and controls
104 lines (104 loc) · 5.64 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Password Generator
import random
import string
import os
from datetime import datetime
print("Welcome to the password Generator!")
History = []
#-------------------------------------------------------------------------------------------
while True:
if not os.path.exists("database.txt"):
with open("database.txt","a") as f:
pass
try:
menu = int(input("\n+--------------------------------------+\n| To Generate Password : Enter [1] |\n| To View Password History : Enter [2] |\n| To Exit : Enter [3] |\n+--------------------------------------+\n"))
#-------------------------------------------------------------------------------------------
if menu == 1:
pool = ""
password = []
characters = []
#-------------------------------------------------------------------------------------------
try:
#-------------------------------------------------------------------------------------------
while True:
uppercase_type = input("\nDo you want to include Uppercase letters for password generation(yes/no)?\n").capitalize().strip()
if uppercase_type == "Yes":
pool += string.ascii_uppercase
print("The Uppercase letters has been added for password generation!\n")
break
elif uppercase_type == "No":
print("The Uppercase letters has not been added for password generation!\n")
break
else:
print("Only Yes and no are available")
#-------------------------------------------------------------------------------------------
while True:
lowercase_type = input("Do you want to include Lowercase letters for password generation(yes/no)?\n").capitalize().strip()
if lowercase_type == "Yes":
pool += string.ascii_lowercase
print("The Lowercase letters has been added for password generation!\n")
break
elif lowercase_type == "No":
print("The Lowercase letters has not been added for password generation!\n")
break
else:
print("Only Yes and no are available")
#-------------------------------------------------------------------------------------------
while True:
number_type = input("Do you want to include Numbers(0-9) for password generation(yes/no)?\n").capitalize().strip()
if number_type == "Yes":
pool += string.digits
print("The Numbers has been added for password generation!\n")
break
elif number_type == "No":
print("The Numbers has not been added for password generation!\n")
break
else:
print("Only Yes and no are available")
#-------------------------------------------------------------------------------------------
while True:
special_type = input("Do you want to include Special for password generation(yes/no)?\n").capitalize().strip()
if special_type == "Yes":
pool += string.punctuation
print("The Special Characters has been added for password generation!\n")
break
elif special_type == "No":
print("The Special Characters has not been added for password generation!\n")
break
else:
print("Only Yes and no are available")
#-------------------------------------------------------------------------------------------
try:
password_len = int(input("Enter the password length:"))
if pool != "" and password_len != 0:
for i in range(password_len):
characters.append(random.choice(pool))
random.shuffle(characters)
password = "".join(characters)
History.append(password)
print(f"Your password is {password}.")
with open("database.txt","a") as f:
f.write(f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}], User created the password: [{password}]\n")
else:
print("You didn't choose any options to make password! The password is not created!")
except:
print("Invalid Input! Error 104")
#-------------------------------------------------------------------------------------------
except:
print("Invalid Input! Error 103")
elif menu == 2:
print("Loading resources...\nFleching data...")
print("Presenting the password histories...")
for i in History:
print(f"Password =>{i} ")
with open("database.txt","a") as f:
f.write(f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}], User checked avaliable passwords: {History}\n")
elif menu == 3:
print("Exiting...")
with open("database.txt","a") as f:
f.write(f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}], User exited the app.\n")
break
else:
print("Invalid Input! Error: 002")
except:
print("Invalid Input! Error:001")