Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added __pycache__/manager.cpython-310.pyc
Binary file not shown.
12 changes: 9 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,24 @@ def main():
elif choice == '4' and validate_key_loaded(pm):
path = input("Enter password file path: ").strip()
pm.load_password_file(path)

elif choice == '5' and validate_key_loaded(pm):
# Password conditions
print("Password must be at least 8 characters long.")
print("Password must contain at least one lowercase letter.")
print("Password must contain at least one uppercase letter.")
print("Password must contain at least one digit.")
print("Password must contain at least one special character.")
site = input("Enter site: ").strip()
password = input("Enter password: ").strip()
if pm.validate_strength(password):
print("added successfully")
else:
print("WARNING: This password is weak, It is recommended to set a stronger password")
print("- Password should be more than 8 characters long")
print("- Password should have alphanumeric characters, capital letters and special characters")
# Printing Exact password weakness is already handled in self.validate_strength() function
pm.add_password(site, password)

elif choice == '6' and validate_key_loaded(pm):

site = input("Enter site: ").strip()
res = pm.get_password(site)
print(f"Password for {site}: {res}")
Expand All @@ -104,6 +109,7 @@ def main():
print("Saved Sites:")
for site in pm.password_dict:
print(site)

elif choice == 'q':
done = True
print("Goodbye!")
Expand Down
26 changes: 24 additions & 2 deletions manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from cryptography.fernet import Fernet




class PasswordManager:

def __init__(self):
Expand Down Expand Up @@ -35,6 +37,7 @@ def load_password_file(self, path):
site, encrypted = line.split(":")
self.password_dict[site] = Fernet(self.key).decrypt(encrypted.encode()).decode()


def add_password(self, site, password):
if site in self.password_dict:
print(f"Warning: A password for the site '{site}' already exists.")
Expand All @@ -45,6 +48,7 @@ def add_password(self, site, password):
encrypted = Fernet(self.key).encrypt(password.encode()).decode()
f.write(f"{site}:{encrypted}\n")


def get_password(self, site):
return self.password_dict.get(site, "Password not found.")
def validate_strength(self, password):
Expand All @@ -57,8 +61,10 @@ def validate_strength(self, password):
has_numeric_characters = False
has_capital_letters = False
has_small_letters = False
if len(password) > 8:
has_good_length = True

# Checking all the conditions
if len(password) >= 8:
has_good_length = True
for chr in password:
if chr in SpecialChar:
has_special_char = True
Expand All @@ -68,6 +74,22 @@ def validate_strength(self, password):
has_small_letters = True
if chr.isdigit():
has_numeric_characters = True
# preparing the log message
error_message = ""
if not has_good_length:
error_message += "Password must be at least 8 characters long.\n"
if not has_special_char:
error_message += "Password must contain at least one special character.\n"
if not has_capital_letters:
error_message += "Password must contain at least one uppercase letter.\n"
if not has_small_letters:
error_message += "Password must contain at least one lowercase letter.\n"
if not has_numeric_characters:
error_message += "Password must contain at least one digit.\n"

if error_message != "":
print(error_message)

return has_numeric_characters and has_good_length and\
has_capital_letters and has_special_char and has_small_letters