28 lines
750 B
Python
28 lines
750 B
Python
from tinydb import TinyDB, Query
|
|
import hasher
|
|
|
|
db = TinyDB("./database.json")
|
|
users = db.table("users");
|
|
|
|
def get_users():
|
|
return (users.all())
|
|
|
|
def get_user_by_email(email: str):
|
|
for user in get_users():
|
|
if (list(user.keys())[0] == email):
|
|
return (user);
|
|
|
|
def user_exist(email: str):
|
|
return (get_user_by_email(email) != None)
|
|
|
|
def add_user(email: str, password: str):
|
|
password_hashed = hasher.hash_text(password)
|
|
users.insert({email: str(password_hashed)});
|
|
|
|
def check_password(email: str, password: str):
|
|
password_hashed = get_user_by_email(email).get(email)
|
|
password_hashed = bytes(password_hashed[2:-1], "utf-8")
|
|
return (hasher.is_same(password, password_hashed))
|
|
|
|
resets = db.table("resets")
|