-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathauthentication.py
More file actions
49 lines (39 loc) · 1.13 KB
/
Copy pathauthentication.py
File metadata and controls
49 lines (39 loc) · 1.13 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
39
40
41
42
43
44
45
46
47
48
49
from dotenv import load_dotenv
import mysql.connector
import os
load_dotenv(dotenv_path='settings.ini')
user_db=mysql.connector.connect(
host=os.getenv('SQL_HOST', None),
user=os.getenv('SQL_USER', None),
passwd=os.getenv('SQL_PASSWORD', None),
database=os.getenv('SQL_DATABASE', None)
)
user_details=user_db.cursor()
def register( user_idf,name,username,passwd):
sql="INSERT INTO user (user_id,name,username,passwod) VALUES (%s, %s, %s, %s)"
val=(user_idf,name,username,passwd)
try:
user_details.execute(sql,val)
user_db.commit()
return 0
except:
return 1
def login(usrname,passwd):
user_details.execute("SELECT username,passwod FROM user")
result=user_details.fetchall()
chk=0
for i in range(len(result)):
temp=[]
temp=result[i]
if temp[0]==usrname and temp[1]==passwd:
chk=chk+1
else:
pass
if chk>0:
return 0
else:
return 1
def searchuser_password():
user_details.execute("SELECT username,passwod FROM user")
userinfo=user_details.fetchall()
return userinfo