From 6f8bac17f27a8897a3b4631a33def1402b16a85e Mon Sep 17 00:00:00 2001 From: Max Countryman Date: Tue, 14 Jun 2011 01:51:59 -0700 Subject: [PATCH] Optional BCRYPT_LOG_ROUNDS parameter may now be added to your app's config --- README.markdown | 3 +-- flaskext/bcrypt.py | 10 +++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.markdown b/README.markdown index e4492e1..a060cf3 100644 --- a/README.markdown +++ b/README.markdown @@ -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) diff --git a/flaskext/bcrypt.py b/flaskext/bcrypt.py index 754f325..364425a 100644 --- a/flaskext/bcrypt.py +++ b/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. @@ -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