-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataBase.py
55 lines (41 loc) · 1.41 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
# # importing hashlib
import hashlib
# # Import SQL lite
import sqlite3 as sq
import threading
# Implementing the DataBase
class Sql:
def __init__(self):
self.connect = sq.connect('/main.db')
self.cursor = self.connect.cursor()
def insert(self, user, email, password):
try:
self.cursor.execute('CREATE TABLE User(Name TEXT, Email TEXT, Pass TEXT)')
self.cursor.execute('INSERT INTO User VALUES(?,?,?)', (user, email, pas_hash(password)))
self.connect.commit()
except:
self.cursor.execute('INSERT INTO User VALUES(?,?,?)', (user, email, pas_hash(password)))
self.connect.commit()
return
def checked(self, user, email, password):
check = self.cursor.execute('SELECT Pass FROM User WHERE Name == ? AND Email == ?', (user, email))
self.connect.commit()
try:
pas = list(*check)[0]
except:
return False
if pas_hash(password) == pas:
return True
else:
return False
def output(self):
data = self.cursor.execute('SELECT * FROM User')
for x in data:
print(x)
def quit(self):
self.connect.close()
# First of all we use sha512 hashing algorithm for hashing the password
def pas_hash(password: str):
hash = hashlib.sha512(password.encode('UTF-8')).hexdigest()
return hash
ob = Sql()