Skip to content

Commit

Permalink
move from bcrypt to flask_bcrypt
Browse files Browse the repository at this point in the history
Closes #77
  • Loading branch information
emillon committed Jan 30, 2015
1 parent 799d87b commit 6eb7351
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
11 changes: 7 additions & 4 deletions app/auth.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import bcrypt
from flask import Blueprint
from flask import current_app
from flask import flash
from flask import redirect
from flask import render_template
from flask import request
from flask import url_for
from flask.ext.bcrypt import Bcrypt
from flask.ext.login import login_user
from flask.ext.login import LoginManager
from flask.ext.login import logout_user
Expand Down Expand Up @@ -33,10 +33,13 @@ def auth_user(login, password):
except NoResultFound:
return None
db_hash = user.password
hashed = bcrypt.hashpw(password.encode('utf-8'), db_hash.encode('ascii'))
if db_hash != hashed:
password = password.encode('utf-8')
db_hash = db_hash.encode('ascii')
bcrypt = Bcrypt(current_app)
if bcrypt.check_password_hash(db_hash, password):
return user
else:
return None
return user


class SignupForm(Form):
Expand Down
6 changes: 3 additions & 3 deletions app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import random
import string

import bcrypt
import koremutake
from flask import current_app
from flask.ext.bcrypt import Bcrypt
from flask.ext.login import current_user
from flask.ext.sqlalchemy import SQLAlchemy

Expand Down Expand Up @@ -80,8 +80,8 @@ def generate(fake):
def set_password(self, clear, workfactor):
if workfactor is None:
workfactor = current_app.config['BCRYPT_WORKFACTOR']
salt = bcrypt.gensalt(workfactor)
self.password = bcrypt.hashpw(clear.encode('utf-8'), salt)
bcrypt = Bcrypt(current_app)
self.password = bcrypt.generate_password_hash(clear.encode('utf-8'), workfactor)

def disable_password(self):
self.password = '!'
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
bcrypt==1.1
coverage==3.7.1
fake-factory==0.4.2
Flask==0.10.1
Flask-Admin==1.0.8
Flask-Assets==0.10
Flask-Bcrypt==0.6.0
Flask-Login==0.2.11
Flask-Migrate==1.3
Flask-Script==2.0.5
Expand Down

0 comments on commit 6eb7351

Please sign in to comment.