|
| 1 | +import sqlite3 |
| 2 | +from hashlib import sha256 |
| 3 | + |
| 4 | +MASTERPW = "1234" |
| 5 | + |
| 6 | +PASSWORD = input("ENTER THE MASTER PASSWORD :-") |
| 7 | + |
| 8 | +while MASTERPW != PASSWORD: |
| 9 | + if MASTERPW != PASSWORD: |
| 10 | + print("Invalid Password\n") |
| 11 | + break |
| 12 | + |
| 13 | +if MASTERPW == PASSWORD: |
| 14 | + print("WELCOME BACK SIR :)") |
| 15 | + |
| 16 | +conn = sqlite3.connect('pass_manager.db') |
| 17 | + |
| 18 | +def create_password(pass_key, service, admin_pass): |
| 19 | + return sha256(admin_pass.encode('utf-8') + service.lower().encode('utf-8') + pass_key.encode('utf-8')).hexdigest()[:15] |
| 20 | + |
| 21 | +def get_hex_key(admin_pass, service): |
| 22 | + return sha256(admin_pass.encode('utf-8') + service.lower().encode('utf-8')).hexdigest() |
| 23 | + |
| 24 | +def get_password(admin_pass, service): |
| 25 | + secret_key = get_hex_key(admin_pass, service) |
| 26 | + cursor = conn.execute("SELECT * from KEYS WHERE PASS_KEY=" + '"' + secret_key + '"') |
| 27 | + |
| 28 | + file_string = "" |
| 29 | + for row in cursor: |
| 30 | + file_string = row[0] |
| 31 | + return create_password(file_string, service, admin_pass) |
| 32 | + |
| 33 | +def add_password(service, admin_pass): |
| 34 | + secret_key = get_hex_key(admin_pass, service) |
| 35 | + |
| 36 | + command = 'INSERT INTO KEYS (PASS_KEY) VALUES (%s);' %('"' + secret_key +'"') |
| 37 | + conn.execute(command) |
| 38 | + conn.commit() |
| 39 | + return create_password(secret_key, service, admin_pass) |
| 40 | + |
| 41 | +if MASTERPW == PASSWORD: |
| 42 | + try: |
| 43 | + conn.execute('''CREATE TABLE KEYS |
| 44 | + (PASS_KEY TEXT PRIMARY KEY NOT NULL);''') |
| 45 | + print("Your safe has been created!\nWhat would you like to store in it today?") |
| 46 | + except: |
| 47 | + print("You have a safe, what would you like to do today?") |
| 48 | + |
| 49 | + |
| 50 | + while True: |
| 51 | + print("\n"+ "*"*15) |
| 52 | + print("Commands:") |
| 53 | + print("Press 1 : TO Genrate a Password") |
| 54 | + print("Press 2 : To Get Stored Password") |
| 55 | + print("Press 3 : Quit") |
| 56 | + print("*"*15) |
| 57 | + input_ = input(":") |
| 58 | + |
| 59 | + if input_ == "3": |
| 60 | + break |
| 61 | + if input_ == "1": |
| 62 | + service = input("What is the name of the service?\n") |
| 63 | + print("\n" + service.capitalize() + " password created:\n" + add_password(service, MASTERPW)) |
| 64 | + if input_ == "2": |
| 65 | + service = input("What is the name of the service?\n") |
| 66 | + print("\n" + service.capitalize() + " password:\n" +get_password(MASTERPW, service)) |
| 67 | + if input_ == "4": |
| 68 | + # print(PRAGMA table_info(table_name);) |
| 69 | + break |
0 commit comments