diff --git a/__pycache__/database.cpython-310.pyc b/__pycache__/database.cpython-310.pyc index 239ce05..7b9825e 100644 Binary files a/__pycache__/database.cpython-310.pyc and b/__pycache__/database.cpython-310.pyc differ diff --git a/__pycache__/email.cpython-310.pyc b/__pycache__/email.cpython-310.pyc new file mode 100644 index 0000000..518c457 Binary files /dev/null and b/__pycache__/email.cpython-310.pyc differ diff --git a/__pycache__/hasher.cpython-310.pyc b/__pycache__/hasher.cpython-310.pyc new file mode 100644 index 0000000..ac17437 Binary files /dev/null and b/__pycache__/hasher.cpython-310.pyc differ diff --git a/database.json b/database.json index f15ea8f..24754f9 100644 --- a/database.json +++ b/database.json @@ -1 +1 @@ -{"users": {"1": {"camille@chauvet.pro": "Fgzf4BY6R8oBfoz6VrHziwxjZiz4dB2cU7FcXP5kh"}}} \ No newline at end of file +{"users": {"1": {"camille@chauvet.pro": "b'$2b$12$AMuNu9CU/lUyaQjDmyWypeVg8beyRA795lrldMGAmHMXaeyfNnke.'"}}} \ No newline at end of file diff --git a/database.py b/database.py index 6ef2d11..71bb00c 100644 --- a/database.py +++ b/database.py @@ -1,4 +1,5 @@ from tinydb import TinyDB, Query +import hasher db = TinyDB("./database.json") users = db.table("users"); @@ -15,7 +16,12 @@ def user_exist(email: str): return (get_user_by_email(email) != None) def add_user(email: str, password: str): - users.insert({email: password}); + password_hashed = hasher.hash_text(password) + users.insert({email: str(password_hashed)}); def check_password(email: str, password: str): - return (get_user_by_email(email).get(email) == password) + 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") diff --git a/flask_session/320444fe8859cda10187fa078aaa3674 b/flask_session/320444fe8859cda10187fa078aaa3674 index b5c66ec..e53970b 100644 Binary files a/flask_session/320444fe8859cda10187fa078aaa3674 and b/flask_session/320444fe8859cda10187fa078aaa3674 differ diff --git a/hash.py b/hash.py deleted file mode 100644 index a9fd82f..0000000 --- a/hash.py +++ /dev/null @@ -1,26 +0,0 @@ -import bcrypt - -# Declaring our password -password = b'GeekPassword' - -# Adding the salt to password -salt = bcrypt.gensalt() -# Hashing the password -hashed = bcrypt.hashpw(password, salt) - -print(salt) -print(type(hashed)) - -salt = hashed[:29] - -print(salt) -print(password == bcrypt.hashpw(password, salt)) -print(password == bcrypt.hashpw(password, salt)) -print(password == bcrypt.hashpw(password, salt)) -print(password == bcrypt.hashpw(password, salt)) -print(password == bcrypt.hashpw(password, salt)) -print(password == bcrypt.hashpw(password, salt)) -print(password == bcrypt.hashpw(password, salt)) -print(password == bcrypt.hashpw(password, salt)) -print(password == bcrypt.hashpw(password, salt)) -print(password == bcrypt.hashpw(password, salt)) diff --git a/hasher.py b/hasher.py new file mode 100644 index 0000000..d4dd36e --- /dev/null +++ b/hasher.py @@ -0,0 +1,9 @@ +import bcrypt + +def hash_text(text:str) -> bytes: + text = bytes(text, "utf-8") + return (bcrypt.hashpw(text, bcrypt.gensalt())) + +def is_same(text:str, hashed: bytes) -> bool: + text = text.encode("utf-8") + return (bcrypt.checkpw(text, hashed)) diff --git a/mail.py b/mail.py new file mode 100644 index 0000000..018f9ac --- /dev/null +++ b/mail.py @@ -0,0 +1,26 @@ +import ssl +import smtplib +from email.message import EmailMessage + +config = { + "server": "ssl0.ovh.net", + "port": 465, + "email": "auto@chauvet.pro", + "password": "#FL7Sf*9hZMkund24$a@46ny7Dx", + "display_name": "no-reply@chauvet.pro" +} + +def send_mail(mail_add:str, subject:str, mail_content:str): + email = EmailMessage() + email['From'] = config["display_name"] + email["To"] = mail_add; + email["subject"] = subject; + email.set_content(mail_content); + + context = ssl.create_default_context(); + + with smtplib.SMTP_SSL(config["server"], config["port"], context=context) as smtp: + smtp.login(config["email"], config["password"]); + smtp.sendmail(config["email"], mail_add, email.as_string()); + +send_mail("camille@chauvet.pro", "test", "text") diff --git a/main.py b/main.py index 699d07f..b1ceb49 100644 --- a/main.py +++ b/main.py @@ -25,6 +25,8 @@ def login(): @app.route('/login', methods=['POST']) def login_post(): + if (not session.get("email")): + return (redirect("/connected")) email = request.form.get('email') password = request.form.get('password') if (not database.user_exist(email)): @@ -45,6 +47,8 @@ def signin(): @app.route('/signin', methods=['POST']) def signup_post(): + if (not session.get("email")): + return (redirect("/connected")) email = request.form.get('email') password = request.form.get('password') repassword = request.form.get('repassword')