Admin passwords are stored hashed. Safety third!

This commit is contained in:
2018-10-18 14:07:13 +02:00
parent b213966b2d
commit 944d16bfe4
3 changed files with 25 additions and 3 deletions
+8 -2
View File
@@ -3,7 +3,7 @@ from flask_login import LoginManager, UserMixin, login_required, login_user, log
from PIL import Image, ImageFont, ImageDraw
import qrcode
from io import BytesIO
import json, random, re, string
import json, random, re, string, hashlib, base64
app = Flask(__name__)
systemURL = 'http://192.168.0.11:5000/' #FULL URL with a '/' at the end
@@ -30,6 +30,8 @@ with open('admins.json', 'r') as infile:
for key, value in adminfile.items():
if key=='secret_key':
app.secret_key = value
elif key=='secret_cookie':
secret_cookie = value.encode('utf-8')
else:
a = Admin(key, value['password'])
@@ -119,7 +121,11 @@ def login():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
if admins[username].password == password:
hasher = hashlib.sha256()
hasher.update(password.encode('utf-8'))
hasher.update(secret_cookie)
hashedpassword = base64.b64encode(hasher.digest()).decode('utf-8')
if admins[username].password == hashedpassword:
login_user(admins[username])
return redirect(request.args.get("next"))
return abort(401)