-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from diox/master
django 1.3 compatibility with dynamic hashers from 1.4
- Loading branch information
Showing
7 changed files
with
64 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,25 @@ | ||
VERSION = (0, 4) | ||
__version__ = '.'.join(map(str, VERSION)) | ||
|
||
def get_dynamic_hasher_names(HMAC_KEYS): | ||
""" | ||
Return base dynamic hasher names for each entry in HMAC_KEYS (we need to | ||
create one hasher class for each key). Names are sorted to make sure | ||
the HMAC_KEYS are tested in the correct order and the first one is always | ||
the first hasher name returned. | ||
""" | ||
algo_name = lambda hmac_id: 'bcrypt{0}'.format(hmac_id.replace('-', '_')) | ||
return [algo_name(key) for key in sorted(HMAC_KEYS.keys(), reverse=True)] | ||
|
||
def get_password_hashers(BASE_PASSWORD_HASHERS, HMAC_KEYS): | ||
""" | ||
Returns the names of the dynamic and regular hashers | ||
created in our hashers file | ||
Return the names of the dynamic and regular hashers | ||
created in our hashers file. | ||
""" | ||
# Where is the bcrypt hashers file located? | ||
hashers_base = 'django_sha2.hashers.{0}' | ||
algo_name = lambda hmac_id: 'bcrypt{0}'.format(hmac_id.replace('-', '_')) | ||
|
||
dynamic_hasher_names = [algo_name(key) for key in HMAC_KEYS.keys()] | ||
dynamic_hasher_names = get_dynamic_hasher_names(HMAC_KEYS) | ||
dynamic_hashers = [hashers_base.format(k) for k in dynamic_hasher_names] | ||
|
||
return dynamic_hashers + list(BASE_PASSWORD_HASHERS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters