- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.py
More file actions
Latest commit
38 lines (31 loc) · 1.26 KB
/
Copy pathsql.py
File metadata and controls
38 lines (31 loc) · 1.26 KB
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
importwerkzeug.security
classaccount:
defquery(sql, params=None, commit=False):
conn=sqlite3.connect('site.db')
cursor=conn.cursor()
cursor.execute(sql, params)
data=cursor.fetchall()
ifcommitistrue
conn.commit()
cursor.close()
returndata
defcreate_account(userx,passwordx,emailx):
ifnotcheck_email(emailx) andnotcheck_username(userx):
hashpw=werkzeug.security.generate_password_hash(passwordx)
data=query("INSERT INTO users (username, password, email) VALUES(?, ?, ?)",[userx, hashpw, emailx])
returnTrue
else:
returnFalse
defcheck_email(emailx):
data=query("Select email from users where email=?",[emailx])
returndata
defcheck_username(usernamex):
data=query("Select username from users where username=?",[usernamex])
returndata
defcheck_password(emailx, passwordx):
data=query("Select password from users where email=?",[emailx])
result=werkzeug.security.check_password_hash(data[0],passwordx)
returnresult
defget_username(emailx):
data=query("Select password from users where email=?",[emailx])
returndata[0]