Fixbug encrypt

This commit is contained in:
Andros Fenollosa 2017-05-18 22:18:48 +02:00
parent 2487ac4030
commit f213a04227

23
app.py
View File

@ -2,11 +2,13 @@ from os import getenv
from ast import literal_eval from ast import literal_eval
from flask import Flask, redirect, url_for, render_template, flash, session from flask import Flask, redirect, url_for, render_template, flash, session
from functools import wraps from functools import wraps
from forms import LoginForm, SignupForm, EmailResetPasswordForm, ResetPasswordForm from forms import LoginForm, SignupForm, \
EmailResetPasswordForm, ResetPasswordForm
from models import db, User from models import db, User
from flask_mail import Mail, Message from flask_mail import Mail, Message
from uuid import uuid4 from uuid import uuid4
from crypt import crypt, mksalt, METHOD_SHA512 from werkzeug.security import generate_password_hash, \
check_password_hash
# CONFIGURATIONS # CONFIGURATIONS
# Flask # Flask
@ -64,9 +66,7 @@ def signup():
my_user = User() my_user = User()
form.populate_obj(my_user) form.populate_obj(my_user)
# Encrypt password # Encrypt password
my_user.password = crypt( my_user.password = generate_password_hash(form.password.data)
form.password.data, mksalt(METHOD_SHA512)
)
db.session.add(my_user) db.session.add(my_user)
# Prepare the account activation email # Prepare the account activation email
msg = Message( msg = Message(
@ -180,9 +180,7 @@ def update_password(email, token):
if my_user: if my_user:
if form.validate_on_submit(): if form.validate_on_submit():
# Encrypt password # Encrypt password
my_user.password = crypt( my_user.password = generate_password_hash(form.password.data)
form.password.data, mksalt(METHOD_SHA512)
)
# Update password # Update password
db.session.add(my_user) db.session.add(my_user)
db.session.commit() db.session.commit()
@ -202,11 +200,10 @@ def login():
if form.validate_on_submit(): if form.validate_on_submit():
# Validate email and password # Validate email and password
email = form.email.data email = form.email.data
password = crypt( my_user = User.query.filter_by(email=email).first()
form.password.data, mksalt(METHOD_SHA512) if my_user and check_password_hash(
) my_user.password,
my_user = User.query.filter_by(email=email, password=password).first() form.password.data):
if my_user:
# Login de usuario # Login de usuario
session['user'] = my_user.id session['user'] = my_user.id
return redirect(url_for('dashboard')) return redirect(url_for('dashboard'))