Skip to content

Commit

Permalink
Optional BCRYPT_LOG_ROUNDS parameter may now be added to your app's c…
Browse files Browse the repository at this point in the history
…onfig
  • Loading branch information
maxcountryman committed Jun 14, 2011
1 parent e32e66c commit 6f8bac1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 1 addition & 2 deletions README.markdown
Expand Up @@ -5,8 +5,7 @@ are provided to override the werkzeug.security hashing functions.

To use, simply do the following:

from flaskext.bcrypt import bcrypt_init, generate_password_hash,
check_password_hash
from flaskext.bcrypt import bcrypt_init, generate_password_hash, check_password_hash

bcrypt_init(app)

Expand Down
10 changes: 7 additions & 3 deletions flaskext/bcrypt.py
@@ -1,11 +1,15 @@
from __future__ import absolute_import
import bcrypt

_log_rounds = 12

def bcrypt_init(app):
pass
rounds = app.config.get('BCRYPT_LOG_ROUNDS', None)
print(rounds)
if rounds:
_log_rounds = rounds

def generate_password_hash(password, log_rounds=12):
def generate_password_hash(password):
'''Generates a password hash using `bcrypt`. Specifying `log_rounds` sets
the log_rounds parameter of `bcrypt.gensalt()` which determines the
complexity of the salt. 12 is the default value.
Expand All @@ -18,7 +22,7 @@ def generate_password_hash(password, log_rounds=12):

password = str(password)

pw_hash = bcrypt.hashpw(password, bcrypt.gensalt(log_rounds))
pw_hash = bcrypt.hashpw(password, bcrypt.gensalt(_log_rounds))

return pw_hash

Expand Down

0 comments on commit 6f8bac1

Please sign in to comment.