Skip to content
Open
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
50 changes: 34 additions & 16 deletions PasswordManager/password_manager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import sqlite3
from hashlib import sha256

Expand All @@ -12,13 +11,22 @@
if connect == "q":
break

conn = sqlite3.connect('pass_manager.db')
conn = sqlite3.connect("pass_manager.db")


def create_password(pass_key, service, admin_pass):
return sha256(admin_pass.encode('utf-8') + service.lower().encode('utf-8') + pass_key.encode('utf-8')).hexdigest()[:15]
return sha256(
admin_pass.encode("utf-8")
+ service.lower().encode("utf-8")
+ pass_key.encode("utf-8")
).hexdigest()[:15]


def get_hex_key(admin_pass, service):
return sha256(admin_pass.encode('utf-8') + service.lower().encode('utf-8')).hexdigest()
return sha256(
admin_pass.encode("utf-8") + service.lower().encode("utf-8")
).hexdigest()


def get_password(admin_pass, service):
secret_key = get_hex_key(admin_pass, service)
Expand All @@ -29,40 +37,50 @@ def get_password(admin_pass, service):
file_string = row[0]
return create_password(file_string, service, admin_pass)


def add_password(service, admin_pass):
secret_key = get_hex_key(admin_pass, service)

command = 'INSERT INTO KEYS (PASS_KEY) VALUES (%s);' %('"' + secret_key +'"')
command = "INSERT INTO KEYS (PASS_KEY) VALUES (%s);" % ('"' + secret_key + '"')
conn.execute(command)
conn.commit()
return create_password(secret_key, service, admin_pass)


if connect == ADMIN_PASSWORD:
try:
conn.execute('''CREATE TABLE KEYS
(PASS_KEY TEXT PRIMARY KEY NOT NULL);''')
conn.execute(
"""CREATE TABLE KEYS
(PASS_KEY TEXT PRIMARY KEY NOT NULL);"""
)
print("Your safe has been created!\nWhat would you like to store in it today?")
except:
print("You have a safe, what would you like to do today?")



while True:
print("\n"+ "*"*15)
print("\n" + "*" * 15)
print("Commands:")
print("q = quit program")
print("gp = get password")
print("sp = store password")
print("*"*15)
print("*" * 15)
input_ = input(":")

if input_ == "q":
break
if input_ == "sp":
service = input("What is the name of the service?\n")
print("\n" + service.capitalize() + " password created:\n" + add_password(service, ADMIN_PASSWORD))
print(
"\n"
+ service.capitalize()
+ " password created:\n"
+ add_password(service, ADMIN_PASSWORD)
)
if input_ == "gp":
service = input("What is the name of the service?\n")
print("\n" + service.capitalize() + " password:\n"+get_password(ADMIN_PASSWORD, service))



print(
"\n"
+ service.capitalize()
+ " password:\n"
+ get_password(ADMIN_PASSWORD, service)
)