forked from probablyadev/DFN-Maintenance-GUI-Backend
-
Notifications
You must be signed in to change notification settings - Fork 1
/
model.py
52 lines (44 loc) · 1.28 KB
/
model.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
"""""
* * * * * * * * * *
* Filename: model.py
*
* Purpose: Queries the auth database for the DFN Maintenance GUI
*
* Copyright: 2017 Fireballs in the Sky, all rights reserved
*
* * * * * * * * * *
"""""
import sqlite3
import hashlib
"""""
* Name: loginAuth
*
* Purpose: Checks whether login credentials are correct according to the database
*
* Params: username: A string; the input username
* password: A string; the input password
*
* Return: A boolean, true if authorized successfully and false if invalid credentials
*
* Notes: None
"""""
def loginAuth(username, password):
auth = False
# Connect to database
authdb = sqlite3.connect('db/auth.db')
curs = authdb.cursor()
# Get salt
curs.execute("SELECT salt FROM Authdata WHERE username =?", (username,))
salt = curs.fetchone()
# Hash entered PW with salt
if salt is not None:
hashedpw = hashlib.sha1(salt[0] + password).hexdigest()
else:
hashedpw = ' '
# Query database
dataarray = (username, hashedpw)
check = curs.execute("SELECT * FROM Authdata WHERE username=? AND password=?", dataarray)
# If query returned a result, return true. Otherwise, return false.
if check.fetchone():
auth = True
return auth