osmanYusuf's picture
upload files
5eeafe5 verified
# # auth.py
# import sqlite3
# import bcrypt
#
#
# def create_connection():
# conn = sqlite3.connect('database.db')
# return conn
#
#
# def signup(username, password):
# conn = create_connection()
# cursor = conn.cursor()
# hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
# cursor.execute('INSERT INTO users (username, password) VALUES (?, ?)', (username, hashed_password))
# conn.commit()
# conn.close()
#
#
# def login(username, password):
# conn = create_connection()
# cursor = conn.cursor()
# cursor.execute('SELECT password FROM users WHERE username = ?', (username,))
# user_data = cursor.fetchone()
# conn.close()
#
# if user_data:
# hashed_password = user_data[0]
# if bcrypt.checkpw(password.encode('utf-8'), hashed_password.encode('utf-8')):
# return True
# return False
import sqlite3
import bcrypt
def create_connection():
conn = sqlite3.connect('database.db')
return conn
def signup(username, password):
conn = create_connection()
cursor = conn.cursor()
hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
cursor.execute('INSERT INTO users (username, password) VALUES (?, ?)', (username, hashed_password))
conn.commit()
conn.close()
def login(username, password):
conn = create_connection()
cursor = conn.cursor()
cursor.execute('SELECT password FROM users WHERE username = ?', (username,))
user_data = cursor.fetchone()
conn.close()
if user_data:
hashed_password = user_data[0]
if bcrypt.checkpw(password.encode('utf-8'), hashed_password.encode('utf-8')):
return True
return False