generated from TempeHS/Secure_Flask_PWA_Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabaseManagement.py
56 lines (51 loc) · 1.81 KB
/
databaseManagement.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
import sqlite3 as sql
db_path = "./.databaseFiles/database.db"
def insertUser(username, hashed_password, totp_secret):
con = sql.connect(db_path)
cur = con.cursor()
# Check if the username already exists
cur.execute("SELECT COUNT(*) FROM secure_users_9f WHERE username = ?", (username,))
if cur.fetchone()[0] > 0:
con.close()
raise Exception("Username already exists")
cur.execute(
"INSERT INTO secure_users_9f (username, password, totp_secret) VALUES (?, ?, ?)",
(username, hashed_password, totp_secret),
)
con.commit()
con.close()
def retrieveUserByUsername(username):
conn = sql.connect(db_path)
cur = conn.cursor()
cur.execute(
"SELECT * FROM secure_users_9f WHERE username = ?",
(username,)
)
user = cur.fetchone()
conn.close()
if user:
return {
'id': user[0],
'username': user[1],
'password': user[2],
'totp_secret': user[3] # Assuming the totp_secret is stored in the 4th column
}
return None
def updateUserTotpSecret(username, totp_secret):
conn = sql.connect(db_path)
cur = conn.cursor()
cur.execute(
"UPDATE secure_users_9f SET totp_secret = ? WHERE username = ?",
(totp_secret, username)
)
conn.commit()
conn.close()
def insertLogEntry(developer, project, start_time, end_time, time_worked, repo, developer_notes, developer_code):
con = sql.connect(db_path)
cur = con.cursor()
cur.execute(
"INSERT INTO log_entries_9f3b2 (developer, project, start_time, end_time, time_worked, repo, developer_notes, developer_code) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
(developer, project, start_time, end_time, time_worked, repo, developer_notes, developer_code),
)
con.commit()
con.close()