-
Notifications
You must be signed in to change notification settings - Fork 0
/
access_user.py
36 lines (26 loc) · 912 Bytes
/
access_user.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
def verify(username, password):
'''This function retrieves user data from the
database and check it against password provided'''
import sqlite3
# Connect/ Create this databse file
conn = sqlite3.connect('user_data.db')
# creating a cursor object to execute sql commands
cursor = conn.cursor()
cursor.execute("SELECT * FROM users WHERE username=?", (username,))
user = cursor.fetchone()
if user and user[2] == password:
authority = user[3]
conn.close()
return authority
conn.close()
return None # invalid credentials oR USER don't exist
def get_all_data():
'''raw data of all users'''
import sqlite3
conn = sqlite3.connect('user_data.db')
cursor = conn.cursor()
# Fetch all data
cursor.execute("SELECT * FROM users")
data = cursor.fetchall()
conn.close()
return data