password hasheds
This commit is contained in:
parent
8fe3dccfd2
commit
39574a2c06
Binary file not shown.
BIN
__pycache__/email.cpython-310.pyc
Normal file
BIN
__pycache__/email.cpython-310.pyc
Normal file
Binary file not shown.
BIN
__pycache__/hasher.cpython-310.pyc
Normal file
BIN
__pycache__/hasher.cpython-310.pyc
Normal file
Binary file not shown.
@ -1 +1 @@
|
||||
{"users": {"1": {"camille@chauvet.pro": "Fgzf4BY6R8oBfoz6VrHziwxjZiz4dB2cU7FcXP5kh"}}}
|
||||
{"users": {"1": {"camille@chauvet.pro": "b'$2b$12$AMuNu9CU/lUyaQjDmyWypeVg8beyRA795lrldMGAmHMXaeyfNnke.'"}}}
|
10
database.py
10
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")
|
||||
|
Binary file not shown.
26
hash.py
26
hash.py
@ -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))
|
9
hasher.py
Normal file
9
hasher.py
Normal file
@ -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))
|
26
mail.py
Normal file
26
mail.py
Normal file
@ -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")
|
4
main.py
4
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')
|
||||
|
Loading…
Reference in New Issue
Block a user