0% found this document useful (0 votes)
19 views28 pages

Test119 2

Uploaded by

marak58871
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views28 pages

Test119 2

Uploaded by

marak58871
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 28

S.

no Contents Pg no Signature
1. Introduction 1
2. Synopsis 2
3. Objective of the program 3
4. Errors and its types 4

5. Testing 5

6. Maintenance 6

7. Modules used 7

8. Function used 8

9. System requirements 9

10. Flow chart 10

11. Source code 11

12. Sample output 15

14. Conclusion 17

14. Bibliography 19

INDEX
INTRODUCTION:

In this project, we have created a Password Management


System using Python. The purpose of this project is to help
users securely store and retrieve their passwords for various
websites and services. This is an important concept in modern-
day programming as password security is a major concern.
With this program, passwords are encrypted to ensure they are
safely stored and not exposed in plain text.

The main goal of this project is to teach how to securely


manage passwords by implementing encryption and decryption
in a simple and understandable way. This provides a foundation
for more advanced password management tools, which can
include features such as user authentication, password
strength checking, and cloud-based storage.

This code can be the foundation for a more advanced password


manager, where additional features like user authentication,
password strength checking, or even integration with cloud
services can be added.

SYNOPSIS:

1
This Password Management System is a Python-based
project that allows users to securely store, retrieve, and
manage passwords for different websites. The system uses
encryption techniques to ensure that passwords are stored
safely and cannot be accessed without proper decryption. This
project aims to address the common need for secure password
storage while providing an easy-to-use interface for interacting
with stored credentials.

1. Password Encryption:

 The system uses the cryptography library to encrypt and


decrypt passwords, ensuring that even if the password file
is exposed, the information remains unreadable without
the encryption key.

2. Password Storage:

 Encrypted passwords are stored in a text file, along with


the associated website name. This ensures that each
password is linked to a specific website for easy retrieval.

3. Password Retrieval:

 Users can retrieve their password for a specific website.


The password is decrypted from the stored file using the
secret key, which ensures that only authorized users can
access the passwords.

4. Key Management:

 The system generates a unique encryption key


(secret.key), which is used for encrypting and decrypting
passwords. This key must be kept secure to maintain the
integrity of the system.

OBJECTIVE OF THIS PROJECT:

2
The primary objective of this Password Management
System project is to develop a secure, simple, and easy-to-use
tool that allows users to store, manage, and retrieve their
passwords safely. The system uses encryption techniques to
protect sensitive password data, ensuring that it is not exposed
in plain text, even if the storage file is compromised.

Specific Objectives:

1. Secure Password Storage:


o Implement encryption to securely store passwords
and prevent unauthorized access. This ensures that
passwords are not stored in a readable format in the
system.
2. Password Retrieval:
o Enable users to retrieve their saved passwords by
providing the associated website name. The system
will decrypt the password to show it only to
authorized users.
3. Data Protection through Encryption:
o Use the cryptography library to encrypt and decrypt
passwords, ensuring data confidentiality. The
passwords are encrypted before being saved and
only decrypted when retrieved by the user.
4. File Management:
o Store encrypted passwords in a text file
(passwords.txt) and the encryption key in a separate
file (secret.key). This ensures passwords are not
exposed while maintaining a simple and functional
file structure for storage.
5. User-Friendly Interface:
o Provide an easy-to-use, text-based interface where
users can interact with the system to add, retrieve,
and manage passwords for different websites.
6. Demonstrate Key Security Concepts:
o Introduce the concept of symmetric encryption (using
a single key for both encryption and decryption) and
highlight the importance of key management in
password security.
7. Educational Purpose:

3
o Serve as an educational tool to demonstrate secure
password handling, file I/O in Python, and basic
cryptographic techniques to students or beginners
learning about data security.

By achieving these objectives, the project helps users


understand the importance of protecting passwords and
demonstrates how to implement a basic, secure password
management system using Python.

ERRORS AND ITS TYPES:

4
An error, sometime called “A BUG” is anything in the code that
prevents a program from compiling and running correctly.

There are broadly three types of errors as follows:

1. Compile - time errors: Errors that occurs during


compilation of a program is called compile time error. It has
two types as follows:

a. Syntax error: It refers to formal rules governing the


construction of valid statements in a language.

b. Semantics error: It refers to the set of rules which give the


meaning of a statement.

2. Run time Errors: Errors that occur during the execution of


program are run time errors. These are harder to detect errors.
Some run-time error stops the execution of program which is
then called program “Crashed”.

3. Logical Errors: Sometimes, even if you don’t encounter any


error during compiling-time and runtime, your program does
not provide the correct result. This is because of the
programmer’s mistaken analysis of the problem he or she is
trying to solve. Such errors are called logical error.

TESTING:

5
1. Alpha Testing: It is the most common type of testing used
in the software industry. The objective of this testing is to
identify all possible issues or defects before releasing it into the
market or to the user. It is conducted at the developer’s site.

2. Beta Testing: It is a formal type of software testing which is


carried out by the customers. It is performed in a real
environment before releasing the products into the market for
the actual end-users. It is carried out to ensure that there are
no major failures in the software or product and it satisfies the
business requirement. Beta Testing is successful when the
customer accepts the software.

3. White Box Testing: White box testing is based on the


knowledge about the internal logic of an application’s code. It is
also known as Glass box Testing. Internal Software and code
working should be known for performing this type of testing.
These tests are based on the coverage of the code statements,
branches, paths, conditions etc.

4. Black Box Testing: It is a software testing, method in


which the internal structure or design of the item to be tested is
not known to the tester. This method of testing can be applied
virtually to every level of the software testing.

MAINTENANCE

Programming maintenance refers to the modifications in the


program. After it has been completed, in order to meet
6
changing requirement or to take care of the errors that shown
up. There are four types of maintenance:

1.Corrective Maintenance: When the program after


compilation shows error because of some unexpected
situations, untested areas such errors are fixed up by
Corrective maintenance.

2.Adaptive Maintenance: Changes in the environment in


which an information system operates may lead to system
management. To accommodate changing needs time to time
maintenance is done and is called Adaptive maintenance.

3. Preventive Maintenance: If possible, the errors could be


anticipated before they actually occur; the maintenance is
called Preventive maintenance.

4. Perfective Maintenance: In this rapidly changing world,


information technology is the fastest growing area. If the
existing system is maintained to keep tuned with the new
features, new facilities, new capabilities, it is said to be
Perfective maintenance.

7
MODULES USED
1. os Module

The os module in Python provides a way to interact with the


operating system, allowing you to perform various tasks like file
handling, directory operations, and environment variable
management. It gives a way to interact with the file system,
manage paths, and execute system commands.

2. random Module

The random module provides functions to generate random


numbers and select random items from sequences, such as
lists, strings, and tuples. It is commonly used for creating
random data in applications like games, simulations, or even
password generation.

3. cryptography.fernet Module

The cryptography.fernet module is part of the cryptography


package and provides symmetric (secret key) encryption and
decryption. It uses the Fernet encryption system, which is
designed to be both secure and easy to use. It ensures the
confidentiality of data by encrypting and decrypting it with the
same secret key.

4. string Module

The string module contains common string operations and


constants, such as predefined sets of characters like digits,
punctuation, and whitespace. It is useful for manipulating and
working with strings in Python.

8
FUNCTIONS USED
1. generate_key()

 Purpose: This function generates a new encryption key


using the Fernet method from the cryptography library
and writes the key to a file called secret.key.

2. load_key()

 Purpose: This function loads the encryption key from the


file secret.key, which was created by the generate_key()
function.

3. encrypt_text(password)

 Purpose: This function encrypts a given password using


the provided encryption key.

4. decrypt_password(encrypted_password)

 Purpose: This function decrypts an encrypted password


using the provided encryption key.

5. add_password(website, password, key)

 Purpose: This function adds a new password entry for a


website to the password file (passwords.txt).

6. retrieve_password(website, key)

 Purpose: This function retrieves the stored password for a


given website from the passwords.txt file.

7. main()

 Purpose: This is the main function that provides a menu


for the user to interact with the password manager. It
handles user input and invokes the appropriate functions
to add or retrieve passwords, or exit the program.

9
SYSTEM REQUIREMENTS

HARDWARE:-
✓ Processor
✓ Keyboard
✓ Minimum memory - 2GB

SOFTWARE:-
✓ Operating System –OS10, OS11
✓ Python IDL

10
FLOWCHART

11
SOURCE CODE

import random

import string

import os

from cryptography.fernet import Fernet

def generate_key():

if not os.path.exists("key.key"):

key = Fernet.generate_key()

with open("key.key", "wb") as key_file:

key_file.write(key)

else:

with open("key.key", "rb") as key_file:

key = key_file.read()

return key
12
def encrypt_text(text):

key = generate_key()

f = Fernet(key)

encrypted_text = f.encrypt(text.encode())

return encrypted_text

def decrypt_text(encrypted_text):

key = generate_key()

f = Fernet(key)

decrypted_text = f.decrypt(encrypted_text.encode()).decode()

return decrypted_text

def generate_easy_password(length=8):

characters = string.ascii_lowercase + string.digits

return ''.join(random.choice(characters) for _ in range(length))

def generate_complicated_password(length=12):

characters = string.ascii_letters + string.digits +


string.punctuation

13
return ''.join(random.choice(characters) for _ in range(length))

def save_password(subject, password,


filename="passwords.txt"):

encrypted_password = encrypt_text(password)

with open(filename, "a") as file:

file.write(f"{subject}:{encrypted_password.decode()}\n")

print(f"\nPassword for {subject} saved successfully!")

def generate_and_save_password():

# Function to generate and save password

subject = input("Enter the subject name (e.g., email, bank


account): ")

while True:

choice = input("Choose password complexity


(easy/complicated): ").strip().lower()

if choice == 'easy':

14
password = generate_easy_password()

break

elif choice == 'complicated':

password = generate_complicated_password()

break

else:

print("Invalid choice. Please choose 'easy' or


'complicated'.")

print(f"Generated password for {subject}: {password}")

# Ask if the user wants to save the password

save_choice = input("Do you want to save this password?


(yes/no): ").strip().lower()

if save_choice == 'yes':

save_password(subject, password)

print("Password saved successfully.")

else:

print("Password not saved.")

15
def view_passwords(filename="passwords.txt"):

if not os.path.exists(filename):

print("No saved passwords found.")

else:

with open(filename, "r") as file:

passwords = file.readlines()

if passwords:

print("Saved Passwords:")

for entry in passwords:

try:

subject, encrypted_password =
entry.strip().split(":")

decrypted_password =
decrypt_text(encrypted_password)

print(f"{subject}: {decrypted_password}")

except ValueError:

print("Error reading entry, invalid format.")


16
else:

print("No passwords saved yet.")

input("\nPress Enter to return to the menu...")

while True:

print("\nPassword Manager")

print("1. Generate and Save Password")

print("2. Manual Save Password")

print("3. View Saved Passwords")

print("4. Exit")

o = input('enter option:')

if o == '1':

generate_and_save_password()

elif o == '2':

sub = input('Enter subject:')

pin = input('enter pin:')

save_password(sub,pin)

17
elif o == '3':

view_passwords()

elif o == '4':

print('tq')

break

18
OUTPUT

19
CONCLUSION
The Password Management System implemented in Python
successfully demonstrates the principles of secure password
storage and encryption using the cryptography.fernet
module. This project highlights key concepts in data security
and provides a basic yet functional tool to manage passwords
safely.

Key Achievements:

1. Secure Password Storage:


o Passwords are encrypted before being saved in the
system, ensuring they are not stored in plain text and
providing a layer of security.
2. Encryption and Decryption:
o The system uses the Fernet symmetric encryption
method to both encrypt and decrypt passwords. The
encryption key is stored securely in a separate file,
which is used for all encryption and decryption
operations.
3. User Interaction:
o The system provides a simple command-line
interface where users can add and retrieve
passwords. The interface is intuitive, requiring
minimal user input while allowing for efficient
password management.
4. File-Based Storage:
o Passwords are stored in a text file (passwords.txt),
where each entry is associated with a website and its
encrypted password. This keeps the system simple
while offering basic password management
capabilities.
5. Security:

20
o By encrypting passwords with a secret key and
ensuring that the key is separate from the data, the
system protects sensitive information from
unauthorized access. However, it also emphasizes
the importance of securely managing the encryption
key.

Limitations and Future Enhancements:

1. Key Management:
o The security of the system depends on how well the
secret.key file is protected. If the key is lost or
compromised, the entire system's security is at risk.
Future versions could include methods to securely
store or generate keys, such as integrating password
protection for the key itself.
2. User Authentication:
o The current system lacks authentication features. To
enhance security, future versions could require a
master password to access the password manager,
ensuring only authorized users can view or modify
stored passwords.
3. Password Strength:
o The system does not currently check or enforce
password strength. Adding a password strength
checker to ensure users are choosing strong, secure
passwords would be an important improvement.
4. Advanced Features:
o The system can be extended to include additional
features, such as:
 Password generation tools for automatically
creating strong passwords.
 Cloud synchronization for accessing passwords
across multiple devices.
 Graphical user interface (GUI) for a more user-
friendly experience.

21
BIBLIOGRAPHY

https://www.interviewbit.com/blog/python-projects/

https://www.w3schools.com/python/

https://pythonworld.in/practical-project/project-list/

import random
import string
import os
from cryptography.fernet import
Fernet

def generate_key():
if not os.path.exists("key.key"):
key = Fernet.generate_key()
with open("key.key", "wb") as
key_file:
key_file.write(key)
else:
with open("key.key", "rb") as
key_file:
key = key_file.read()

return key

22
def encrypt_text(text):
key = generate_key()
f = Fernet(key)
encrypted_text =
f.encrypt(text.encode())
return encrypted_text

def decrypt_text(encrypted_text):
key = generate_key()
f = Fernet(key)
decrypted_text =
f.decrypt(encrypted_text.encode()).d
ecode()
return decrypted_text

def
generate_easy_password(length=8):
characters = string.ascii_lowercase
+ string.digits
return
''.join(random.choice(characters) for
_ in range(length))

def
generate_complicated_password(len
gth=12):
characters = string.ascii_letters +
string.digits + string.punctuation
return
''.join(random.choice(characters) for
_ in range(length))

23
def save_password(subject,
password,
filename="passwords.txt"):
encrypted_password =
encrypt_text(password)
with open(filename, "a") as file:
file.write(f"{subject}:
{encrypted_password.decode()}\n")
print(f"\nPassword for {subject}
saved successfully!")

def generate_and_save_password():
# Function to generate and save
password
subject = input("Enter the subject
name (e.g., email, bank account): ")

while True:
choice = input("Choose password
complexity (easy/complicated):
").strip().lower()

if choice == 'easy':
password =
generate_easy_password()
break
elif choice == 'complicated':

24
password =
generate_complicated_password()
break
else:
print("Invalid choice. Please
choose 'easy' or 'complicated'.")

print(f"Generated password for


{subject}: {password}")

# Ask if the user wants to save the


password
save_choice = input("Do you want
to save this password? (yes/no):
").strip().lower()
if save_choice == 'yes':
save_password(subject,
password)
print("Password saved
successfully.")
else:
print("Password not saved.")

def
view_passwords(filename="passwor
ds.txt"):

25
if not os.path.exists(filename):
print("No saved passwords
found.")
else:
with open(filename, "r") as file:
passwords = file.readlines()
if passwords:
print("Saved Passwords:")
for entry in passwords:
try:
subject,
encrypted_password =
entry.strip().split(":")
decrypted_password =
decrypt_text(encrypted_password)
print(f"{subject}:
{decrypted_password}")
except ValueError:
print("Error reading
entry, invalid format.")
else:
print("No passwords saved
yet.")
input("\nPress Enter to return to
the menu...")

while True:
print("\nPassword Manager")

26
print("1. Generate and Save
Password")
print("2. Manual Save Password")
print("3. View Saved Passwords")
print("4. Exit")
o = input('enter option:')
if o == '1':
generate_and_save_password()

elif o == '2':
sub = input('Enter subject:')
pin = input('enter pin:')
save_password(sub,pin)

elif o == '3':
view_passwords()
elif o == '4':
print('tq')
break

27

You might also like