0% found this document useful (0 votes)
53 views

Code

This document contains code for a password manager program that allows users to: - Store website passwords along with the associated username - Generate secure random passwords of a specified length - Encrypt stored passwords using a user-provided PIN - Delete stored passwords for websites no longer in use - Retrieve and copy encrypted passwords when needed by entering the PIN The program uses a series of functions to handle password generation, encryption/decryption, adding/removing passwords from a stored file, and getting user input to control the program's flow.

Uploaded by

api-708325072
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Code

This document contains code for a password manager program that allows users to: - Store website passwords along with the associated username - Generate secure random passwords of a specified length - Encrypt stored passwords using a user-provided PIN - Delete stored passwords for websites no longer in use - Retrieve and copy encrypted passwords when needed by entering the PIN The program uses a series of functions to handle password generation, encryption/decryption, adding/removing passwords from a stored file, and getting user input to control the program's flow.

Uploaded by

api-708325072
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

import random

import time
from time import sleep
import os
import pyperclip
NUM =
["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","
e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0","!","@"
,"$","%","^","&","*","?","."," "]
print("Hello. This is a password manager program which can do the following:\n---Store passwords\n---Generate secure
passwords\n---Encrypt the passwords\n---Delete useless passwords\nNow please the follow the instuctions carefully and enjoy!\
n")

def god():
#Function for writing the PIN and checking if the PIN is inputed correctly.
def write_p():
PIN_write = "Access key:" + PIN
fhand = open('pass_inf.txt', "r+")
y_there = False
for line in fhand:
line = line.rstrip()
if line.startswith("Access key:"):
n = line
if n != PIN_write:
print ("wrong PIN!")
exit()
y_there = True
break

if y_there == False:
fhand.write("\n"+PIN_write)
fhand.close

#Function for writing all of the information.


def write():
t = open('pass_inf.txt', "a")
t.write("\n"+info_final)
#Function for using the PIN to incrypt the passwords with out the user knowing.
def en_cryption():
key = int(PIN)
global New_message
New_message = ""
n=0
while n < len(message):
index = (NUM.index(message[n],0,72))
final = index + key
if final >= 72:
while final >= 72:
final = final - 72
New_message = New_message + NUM[final]
n=n+1
sleep(.5)

#Generate Funtion for the password.


def Ans_1():
global website_name
global user_name

website_name = input("\nWhat is the name of your website? ---> ")


user_name = input("What is your username? ---> ")
generate()
en_cryption()
global info_final
info_final = ("Website:"+website_name+" User:"+user_name+" Password&"+message)
print("\nYour information is:\n" + info_final)
write()

def generate():
NUM_UPPER =
["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
NUM_LOWER = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
SYM =["!","@","$","%","^","*","?","."]
NUM_noom =["0","1","2","3","4","5","6","7","8","9"]

global message
message = ""
n = input("How long would you like the password to be?\n(Recommended length 6-16)----> ")
try:
int(n)
except:
os.system('cls')
print("Wrong input. Try again!!!")
exit()

if int(n) > 16 or int(n) < 6:


os.system('cls')
print("Wrong input!!!")
god()

g = int(n)
cbrt = g // 4
x = cbrt
y = cbrt
z = cbrt
b = cbrt
while x + y + z + b< g:
x=x+1
break

while x + y + z + b< g:
y=y+1
break

while x + y + z + b< g:
b=b+1
break

while g > 0:
while x > 0:
message = message + random.choice(NUM_UPPER)
x=x-1
break

while y > 0:
message = message + random.choice(NUM_LOWER)
y=y-1
break

while z > 0:
message = message + random.choice(SYM)
z=z-1
break

while b > 0:
message = message + random.choice(NUM_noom)
b=b-1
break
g=g- 1
#Delete Function for removing stored passwords
def remove():
find = input("What is the name of the website you would like to delete your information for? ---->")
global maybe
global found
found = True
maybe = False
with open("pass_inf.txt", "r") as t:
lines = t.readlines()
for i, line in enumerate(lines): #This part of the code is from gabriel
if line.startswith("Website:"+find):
lines[i] = " \n"
maybe = True
with open("pass_inf.txt", "w") as t:
t.writelines(lines)
print("Your information was succesfully deleted!")

#Find function for getting stored passwords.


def restore():
restore = input("What is the name of the website you would like your username and password for? ----> ")
global found
global maybe
maybe = True
found = False
k = open("pass_inf.txt", "r+")
for line in k:
line = line.rstrip()
if line.startswith("Website:"+restore):
found = True
print("Information found and passwrod copied!!!\n")
sleep(.5)
h = line
write_s = False
string = ""
for char in h:
if char == "&":
write_s = True
if write_s == True:
string = string + char
pyperclip.copy(string.replace('&',''))
print(h)

#Function for checking if information has been found or not


def check():
if found == False:
print("Your information was not found!!!")
elif maybe == False:
print("Your information was not found!!!")

#The user function for using the programm.


def instructions():
sleep(.75)
global PIN
PIN = input("Please provide us with your 4 digit pin if you do not have a pin you can create one right now but DO NOT
forget it.\n(If you enter the wrong pin your new passwords will be diffrent and you will not be able to use your saved passwords)\
n---->")
if len(PIN) > 4 or len(PIN) < 4:
os.system('cls')
print("\nWrong input!!!")
god()
try:
int(PIN)
except:
os.system('cls')
print("Wrong input!!!")
god()
global key
sleep(.5)
choice = input("\nWhat would you like to do?\n1.Create and store a new password\n2.Delete an invalid password\n3.Use a
stored password\n----> ")
sleep(.5)
try:
int(choice)
except:
os.system('cls')
print("Wrong input.Try again!!!")
exit()

if int(choice) == 1:
write_p()
Ans_1()
elif int(choice) == 2:
write_p()
remove()
check()
elif int(choice) == 3:
write_p()
restore()
check()
else:
os.system('cls')
print("\nWrong Input!!!")
god()
instructions()
god()

reuse = "Y"
while reuse == "Y":
sleep(.5)
reuse = input("\nWould you like to use this programm again? ----> (Y/N): ")
if reuse == "Y":
sleep(.3)
os.system('cls')
god()
else:
print("Thanks for using this program!")
exit()

You might also like