summaryrefslogtreecommitdiff
path: root/passlib/apps.py
diff options
context:
space:
mode:
authorEli Collins <elic@assurancetechnologies.com>2011-08-12 17:58:09 -0400
committerEli Collins <elic@assurancetechnologies.com>2011-08-12 17:58:09 -0400
commit681ac2f011b86ea9fc26d77b5405b3378e6db7fd (patch)
tree73981123c16583997631f8cff020f7183ae306a3 /passlib/apps.py
parentc475c53326ac1ecf9dc124040d8c1bbed357c0c6 (diff)
downloadpasslib-681ac2f011b86ea9fc26d77b5405b3378e6db7fd.tar.gz
phpass_context now imports bcrypt hash only if phpass_context is used
Diffstat (limited to 'passlib/apps.py')
-rw-r--r--passlib/apps.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/passlib/apps.py b/passlib/apps.py
index 3b5ff2b..02e9f8b 100644
--- a/passlib/apps.py
+++ b/passlib/apps.py
@@ -96,11 +96,17 @@ postgres_context = LazyCryptContext(["postgres_md5"])
#=========================================================
#phpass & variants
#=========================================================
-phpass_context = LazyCryptContext(
- schemes=["bcrypt", "phpass", "bsdi_crypt", ],
+def _create_phpass_policy(**kwds):
+ "helper to make bcrypt default ONLY if it's available"
+ from passlib.context import default_policy
+ if hash.bcrypt.has_backend():
+ kwds['default'] = 'bcrypt'
+ return default_policy.replace(**kwds)
- #XXX: make this lazy as well? causes bcrypt hash to always get loaded
- default="bcrypt" if hash.bcrypt.has_backend() else "phpass",
+phpass_context = LazyCryptContext(
+ schemes=["bcrypt", "phpass", "bsdi_crypt"],
+ default="phpass", #NOTE: <-- overridden by create_policy
+ create_policy=_create_phpass_policy,
)
phpbb3_context = LazyCryptContext(["phpass"], phpass__ident="H")
@@ -114,9 +120,7 @@ phpbb3_context = LazyCryptContext(["phpass"], phpass__ident="H")
_std_roundup_schemes = [ "ldap_hex_sha1", "ldap_hex_md5", "ldap_des_crypt", "roundup_plaintext" ]
roundup10_context = LazyCryptContext(_std_roundup_schemes)
-#FIXME: next roundup will feature ldap_pbkdf2_sha1,
-# but that roundup hasn't been released yet,
-# so version number is unknown... currently guessing at '1.5'
+#NOTE: 'roundup15' really applies to roundup 1.4.17+
roundup_context = roundup15_context = LazyCryptContext(
schemes=_std_roundup_schemes + [ "ldap_pbkdf2_sha1" ],
deprecated=_std_roundup_schemes,