-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.py
58 lines (47 loc) · 1.78 KB
/
project.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
def request_password():
"""
Requests a password from the user and verifies that it has at least 10 characters,
at least one uppercase letter, and at least one number.
"""
while True:
password = input("Enter a password (must have at least 16 characters, at least one uppercase letter, and at least one number): ")
if len(password) >= 16 and any(c.isupper() for c in password) and any(c.isdigit() for c in password):
print("Valid password.")
return password
else:
print("The password must have at least 10 characters, at least one uppercase letter, and at least one number. Try again.")
def save_password(password):
"""
Saves the valid password to a text file named 'passwords.txt'.
"""
with open('passwords.txt', 'a') as file:
file.write(password + '\n')
print("Password saved in 'passwords.txt'.")
def load_passwords():
"""
Reads and displays the stored passwords from the 'passwords.txt' file.
"""
try:
with open('passwords.txt', 'r') as file:
passwords = file.readlines()
if not passwords:
print("No passwords stored.")
else:
print("Stored passwords:")
for i, password in enumerate(passwords, start=1):
print(f"{i}. {password.strip()}")
except FileNotFoundError:
print("'passwords.txt' file does not exist.")
def main():
"""
Main function that executes the program.
"""
print("S.K.I.: Password Management Program")
# Request and validate the password
password = request_password()
# Save the password to a file
save_password(password)
# Load and display stored passwords
load_passwords()
if __name__ == "__main__":
main()