print("You have not installed the required modules. Follow these steps to do so:\n\n1. Open the terminal (Linux/MacOS) or command prompt (Windows).\n2. Navigate to this directory and then to the files directory.\n3. Type 'pip install -r dependencies.txt'.\n4. Restart the program.\n\nIf you have followed all the steps correctly, keyvault will work on the next start.")
exit()
defencrypt_db(password):
binpass=password.encode()
defdatabase_enc():
salt=urandom(16)
conn=sc.connect("database/keyvault.db")
kdf=PBKDF2HMAC(
cursor=conn.cursor()
algorithm=hashes.SHA512(),
ifpath.isfile("database/keyvault.db"):
length=32,
for_inrange(3):
salt=salt,
iterations=1500000,
)
key=base64.urlsafe_b64encode(kdf.derive(binpass))
fernet=Fernet(key)
withopen("database/db.dat","rb")asf:
data=f.read()
encr=fernet.encrypt(data)
withopen("database/db.asc","wb")asf:
f.write(encr)
withopen("database/db.s","wb")asf:
f.write(salt)
defdecrypt_db(password):
withopen("database/db.s","rb")asf:
salt=f.read()
binpass=password.encode()
kdf=PBKDF2HMAC(
algorithm=hashes.SHA512(),
length=32,
salt=salt,
iterations=1500000,
)
key=base64.urlsafe_b64encode(kdf.derive(binpass))
fernet=Fernet(key)
withopen("database/db.asc","rb")asf:
encrypted_data=f.read()
decr=fernet.decrypt(encrypted_data)
withopen("database/db.dat","wb")asf:
f.write(decr)
withopen("database/db.dat","rb")asf:
whileTrue:
try:
try:
db=pickle.load(f)
password=gp(prompt="Enter master password: ")
exceptEOFError:
conn.execute(f"PRAGMA key = {password}")
print("\nDatabase loaded.")
conn.execute('''
CREATETABLEIFNOTEXISTSdata(
idINTEGERPRIMARYKEYAUTOINCREMENT,
serviceTEXT,
usernameTEXT,
emailTEXT,
passwordTEXT,
websiteTEXT,
categoryTEXT,
notesTEXT,
totpTEXT)
''')
passCorrect=True
break
break
shred()
exceptsc.DatabaseError:
print("Incorrect password.\n")
defshred():
passCorrect=False
withopen("database/db.dat","wb")asf:
for_inrange(5):
ifnotpassCorrect:
f.seek(0)
print("You have entered a wrong password three times. Please restart the program to try again.")
f.write(urandom(path.getsize("database/db.dat")))
exit()
remove("database/db.dat")
else:
defclearmem():
print("You have not setup a master password yet. Please set one below.\n")