-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain_def_func.py
53 lines (45 loc) · 1.59 KB
/
main_def_func.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
import sqlite3
from cryptography.fernet import Fernet
def signup(username, password):
# Inserts username and password to database (both are encrypted)
connection = sqlite3.connect("registryUsers.db")
cursor = connection.cursor()
cursor.execute("INSERT INTO users VALUES(?,?)", (username, password))
connection.commit()
connection.close()
def searchUser(key, username, password):
# Compares if the user and password are correct and if the account exists
# Gets a hold of the key of the specified user to decrypt the info
f = Fernet(key)
# Connect to database
conn = sqlite3.connect("registryUsers.db")
# Create a cursor
c = conn.cursor()
# Query database
c.execute("SELECT * FROM users")
items = c.fetchall()
for item in items:
# Decrypts the username of the user
decrypted_user = f.decrypt(item[0])
# Decode the encoded user
original_user = decrypted_user.decode()
# Decrypts the password of the user
decrypted_pass = f.decrypt(item[1])
# Decode the encoded pass
original_pass = decrypted_pass.decode()
if original_user == username and original_pass == password:
return True
# Commit changes
conn.commit()
# Close connection
conn.close()
def tableCreate():
# Creates database table
connection = sqlite3.connect("registryUsers.db")
cursor = connection.cursor()
cursor.execute("""CREATE TABLE users (
username text,
password text
)""")
connection.commit()
connection.close()