From ab87640d1866211e46859077bfd861fcc7c9465a Mon Sep 17 00:00:00 2001 From: Akshat1276 Date: Mon, 16 Dec 2024 23:57:25 +0530 Subject: [PATCH] Added a password length check (minimum length of password should be 8 characters long) #3 --- README.md | 3 ++- main.py | 17 +++++++++++++---- manager.py | 3 +++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ab83ef2..da3eccf 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ Visit the **python** channel and ping `2Y` for assistance. - `4`: Load an existing password file. - `5`: Add a new password to the file. - `6`: Retrieve a password from the file. + - `c`: Clear the CLI - `q`: Quit the application. --- @@ -139,4 +140,4 @@ Password for github is securepassword123 ## Security Note - **Keep Your Encryption Key Safe**: - The encryption key is crucial for accessing your passwords. Losing it means your passwords cannot be decrypted. + The encryption key is crucial for accessing your passwords. Losing it means your passwords cannot be decrypted. \ No newline at end of file diff --git a/main.py b/main.py index 239228c..b1bb8de 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import os #will allow user to interact with the operating system from manager import PasswordManager import pyperclip import sys @@ -39,7 +40,8 @@ def validate_key_loaded(pm : PasswordManager): print("Key not loaded. Please load a key first.") return False return True - +def clear_screen(): #Defining the clear screen function to clear the CLI. + os.system('cls' if os.name == 'nt' else 'clear') #'cls' is used to clear the terminal screen in windows, for Linux, MacOS etc. 'clear' is used def main(): password = { "gmail": "password1", @@ -49,7 +51,7 @@ def main(): pm = PasswordManager() - print("""What would you like to do? + menu = """What would you like to do? 1. Create a new key 2. Load an existing key 3. Create a new password file @@ -57,8 +59,11 @@ def main(): 5. Add a password 6. Get a password 7. List all sites + c. Clear Screen q. Quit - """) + """ + + print(menu) done = False while not done: @@ -104,6 +109,10 @@ def main(): print("Saved Sites:") for site in pm.password_dict: print(site) + elif choice == 'c': #CHECK CONDITION AND CLEAR THE CLI + clear_screen() + print(menu) + print("Cleared the screen.") elif choice == 'q': done = True print("Goodbye!") @@ -112,4 +121,4 @@ def main(): if __name__ == '__main__': - main() + main() \ No newline at end of file diff --git a/manager.py b/manager.py index 863bf35..46f01c3 100644 --- a/manager.py +++ b/manager.py @@ -39,6 +39,9 @@ def add_password(self, site, password): if site in self.password_dict: print(f"Warning: A password for the site '{site}' already exists.") return + while len(password) < 8: #ENSURES THAT PASSWORD IS ATLEAST 8 CHARACTERS LONG + print("Error: Password must be at least 8 characters long.") + password = input("Please enter a valid password: ").strip()#WILL CONTINUE PROMPTING USER TO ENTER THE PASSWORD IN THE CORRECT FORMAT self.password_dict[site] = password if self.password_file is not None: with open(self.password_file, 'a+') as f: