def get_passwords(master, account): # Get passwords from the database path = detect_path() decryptDB(path, master) # Setup DB conn = sqlite3.connect(path) with conn: c = conn.cursor() if account: c.execute("SELECT * FROM passwords WHERE account=?", (account, )) password = c.fetchone() if password: copy_text(decrypt_pass(password[2], master)) print("Password has been copied to your clipboard!") else: print("The specified account does not exist!") else: c.execute("SELECT * FROM passwords") passwords = c.fetchall() for password in passwords: print("{} = {}".format(password[1], decrypt_pass(password[2], master))) conn.close() encryptDB(path, master)
def add_password(master, account, password): # Adds a new password profile to the database path = detect_path() decryptDB(path, master) # Encrypt pass password = encrypt_pass(password, master) # Setup DB conn = sqlite3.connect(path) with conn: c = conn.cursor() c.execute("SELECT * FROM passwords WHERE account=?", (account, )) r = True if c.fetchone(): # the account already exists; so replace it confirm = input( "The password already exists; Do you wish to overwrite it (y/n)? " ) r = False if confirm.lower() in ["y", "yes"]: cmd = """UPDATE passwords SET password = ? WHERE account = ?""" c.execute(cmd, (password, account)) if r: cmd = """INSERT INTO passwords(account, password) VALUES (?, ?)""" c.execute(cmd, (account, password)) conn.close() encryptDB(path, master) return True
def check_master(master): # Check if a given master password is valid or not path = detect_path() if decryptDB(path, master, inplace=False): os.remove(path) return True return False
def delete_profile(master, account=None): # Delete a password profile from the database path = detect_path() decryptDB(path, master) # Setup DB conn = sqlite3.connect(path) with conn: c = conn.cursor() if account: cmd = "DELETE FROM passwords WHERE account = ?" c.execute(cmd, (account, )) else: cmd = "DELETE FROM passwords" c.execute(cmd) conn.close() encryptDB(path, master)
def resetDB(master): # Reset all the passwords in the database path = detect_path() decryptDB(path, master) # Setup DB conn = sqlite3.connect(path) with conn: c = conn.cursor() c.execute("SELECT * FROM passwords") passwords = c.fetchall() for password in passwords: new_pass = encrypt_pass(generate_password(), master) cmd = """UPDATE passwords SET password = ? WHERE id = ?""" c.execute(cmd, (new_pass, password[0])) conn.close() encryptDB(path, master)