Skip to content

Commit

Permalink
wrote database manager module
Browse files Browse the repository at this point in the history
  • Loading branch information
Equat-ion committed Jan 19, 2025
1 parent 95fb45d commit 2cd5273
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions core/database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import json
import os

class Database:
def __init__(self, filepath="passwords.json"):

self.filepath = filepath

if not os.path.exists(self.filepath):
with open(self.filepath, 'w') as db:
json.dump([], db)

def read_data(self):
with open(self.filepath, 'r') as db:
return json.load(db)

def write_data(self,data):
with open(self.filepath, 'w') as db:
json.dump(data, db, indent=4)

def add_password(self, service, userid, encrypted_password):
data = self.read_data()
entry = {
"service": service,
"userid": userid,
"encrypted_password": encrypted_password
}

data.append(entry)
self.write_data(data)

def get_passwords(self):
return self.read_data()

0 comments on commit 2cd5273

Please sign in to comment.