Coders Packet

Key for Password Security Using Python

By ABHISHEK KUMAR

In this Project, a Random password can generate, add a password, retrieve stored password, and delete a stored password.

CONTENTS:-

1. Project information

2. Project Requirement

3. Details

4. Source code

5. Output

Project Information:-

This project is for how can be secure password. And also in this project We stored the password in the file. This project helps many users for storing passwords because it is difficult to remember many passwords at a single time for many websites. And also They can't use a single password for any website because it is not secure. So This project helps such users. In this Digital world Hackers will always try to break password security. So we should use more to secure longer passwords using symbols.

Project Requirement:- 

1. Import String

pip install string

2. Import Json

pip install json

Details:-

The code asks the to user write a file name in which the password is to be stored.

Password is very important for everyone. If the password leaks then our information will be leaked. so we should secure the password.

Then it will show 5 options.

1st option Generate Random Password.

2nd option Add a password

3rd option shows the Retrieve password which was saved in the file.

4th option shows to delete a saved password

5th option shows the exit option.

project source code saved with filename.py and import necessary library through cmd in windows then run python filename.py then it will show all above option. Then you will use it according to your needs. 

Source code:- 

import random
import string
import json

class PasswordManager:
    def __init__(self):
        self.passwords = {}
        self.password_file = ""

    def generate_password(self, length=12):
        lowercase_letters = string.ascii_lowercase
        uppercase_letters = string.ascii_uppercase
        digits = string.digits
        symbols = string.punctuation
        all_characters = lowercase_letters + uppercase_letters + digits + symbols
        password = ''.join(random.choice(all_characters) for _ in range(length))
        return password

    def set_password_file(self, file_name):
        self.password_file = file_name

    def load_passwords(self):
        try:
            with open(self.password_file, "r") as file:
                self.passwords = json.load(file)
        except FileNotFoundError:
            self.passwords = {}

    def save_passwords(self):
        with open(self.password_file, "w") as file:
            json.dump(self.passwords, file)

    def add_password(self, website, username, password):
        if website in self.passwords:
            print("Password for website '{}' already exists. Updating the existing password...".format(website))
        self.passwords[website] = {"username": username, "password": password}
        self.save_passwords()
        print("Password added/updated successfully!")

    def get_password(self, website):
        if website in self.passwords:
            return self.passwords[website]
        return None

    def delete_password(self, website):
        if website in self.passwords:
            del self.passwords[website]
            self.save_passwords()
            print("Password for website '{}' deleted successfully!".format(website))
        else:
            print("Password for website '{}' not found.".format(website))


# Create an instance of PasswordManager
password_manager = PasswordManager()

file_name = input("Enter the password file name: ")
password_manager.set_password_file(file_name)
password_manager.load_passwords()
print("Password file set to '{}'.".format(file_name))

while True:
    print("SecurePass: Python Password Manager and Generator")
    print("1. Generate a random password")
    print("2. Add a password")
    print("3. Retrieve a password")
    print("4. Delete a password")
    print("5. Exit")

    choice = input("Enter your choice (1-5): ")

    if choice == "1":
        length = int(input("Enter the length of the password: "))
        password = password_manager.generate_password(length)
        print("Generated Password:", password)
    elif choice == "2":
        website = input("Enter the website: ")
        username = input("Enter the username: ")
        password = input("Enter the password: ")
        password_manager.add_password(website, username, password)
    elif choice == "3":
        website = input("Enter the website: ")
        stored_password = password_manager.get_password(website)
        if stored_password:
            print("Website:", website)
            print("Username:", stored_password["username"])
            print("Password:", stored_password["password"])
        else:
            print("Password not found for website '{}'.".format(website))
    elif choice == "4":
        website = input("Enter the website: ")
        password_manager.delete_password(website)
    elif choice == "5":
        break
    else:
        print("Invalid choice. Please try again.\n")

Output:-

ouput key passwordoutput2 key password

Download Complete Code

Comments

No comments yet

Download Packet

Reviews Report

Submitted by ABHISHEK KUMAR (ABHISHEK241)

Download packets of source code on Coders Packet