-
Notifications
You must be signed in to change notification settings - Fork 0
/
Database.py
67 lines (52 loc) · 1.56 KB
/
Database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sqlite3
from datetime import datetime
conn = sqlite3.connect("database.db")
c = conn.cursor()
def get_time():
today = datetime.today().strftime("%d/%m/%y %I:%M%p")
return today
def create_database():
c.execute("""CREATE TABLE IF NOT EXISTS encrypts_storage(
web TEXT NOT NULL,
usr TEXT NOT NULL,
pswd TEXT NOT NULL,
create_date TEXT,
last_used TEXT,
PRIMARY KEY (web, usr))""")
return
def create_account(web, usr, pswd):
curr_date = get_time()
c.execute("""INSERT INTO encrypts_storage
(web, usr, pswd, create_date, last_used)
VALUES (?, ?, ?, ?, ?)""",
(web, usr, pswd, curr_date, curr_date))
conn.commit()
return
def search_account(web, usr):
c.execute("""SELECT *
FROM encrypts_storage
WHERE web=? AND usr=?""",
(web, usr))
data = c.fetchall()
attrs = ["website", "username", "password", "last_used", "create_date"]
data = dict(zip(attrs, data[0])) if data else None
return data
def delete_account(web, usr):
c.execute("""DELETE FROM encrypts_storage
WHERE web=? AND usr=?""",
(web, usr))
conn.commit()
return
def update_account(web, usr, new_usr, new_pswd):
curr_date = get_time()
c.execute("""UPDATE encrypts_storage
SET usr=?, pswd=?, last_used=?
WHERE web=? AND usr=?""",
(new_usr, new_pswd, curr_date, web, usr))
conn.commit()
return
def show_all():
c.execute("""SELECT web, usr, create_date, last_used
FROM encrypts_storage""")
data = c.fetchall()
return data