Skip to content

Commit

Permalink
Encrypt the passwords.
Browse files Browse the repository at this point in the history
  • Loading branch information
WeepingDogel committed Jan 19, 2023
1 parent be53792 commit 26b0ebf
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions flaskr/auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Authorization

import functools,time,os,uuid,cv2, shutil
import functools,time,os,uuid,cv2, shutil,hashlib
from flaskr.db import get_db
from flask import(
Blueprint,
Expand All @@ -21,6 +21,7 @@ def register():
if request.method == 'POST':
userName = request.form['username']
passWord = request.form['password']
passWordToStore = hashlib.sha512(passWord.encode('utf-8')).hexdigest()
repeatPassword = request.form['repeat_password']
Email = request.form['email']
Date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
Expand All @@ -30,7 +31,7 @@ def register():
elif passWord == repeatPassword:
try:
db.execute("INSERT INTO USERS(UserName, PassWord, Email, Date) VALUES(?, ?, ?, ?)",
(userName, passWord, Email, Date))
(userName, passWordToStore, Email, Date))
db.commit()
os.mkdir(current_app.config['USERFILE_DIR'] + "/" + userName)
os.mkdir(current_app.config['USERFILE_DIR'] + "/" + userName + "/Images")
Expand All @@ -53,7 +54,8 @@ def login():
).fetchone()
if users is None:
return "User doesn't exist. <a href='/login_and_register'>Back</a>"
elif passWord != users['PassWord']:

elif hashlib.sha512(passWord.encode('utf-8')).hexdigest() != users['PassWord']:
return "Incorrect password. <a href='/login_and_register'>Back</a>"
else:
session.clear()
Expand Down

0 comments on commit 26b0ebf

Please sign in to comment.