2015-10-22 13:51:16 +00:00
|
|
|
"""`di.Callable` providers with keyword arguments example."""
|
2015-07-15 21:49:20 +00:00
|
|
|
|
2015-09-02 15:48:11 +00:00
|
|
|
import passlib.hash
|
|
|
|
import dependency_injector as di
|
2015-07-15 21:49:20 +00:00
|
|
|
|
2015-07-15 23:39:21 +00:00
|
|
|
# Password hasher and verifier providers (hash function could be changed
|
|
|
|
# anytime (for example, to sha512) without any changes in client's code):
|
2015-09-02 15:48:11 +00:00
|
|
|
password_hasher = di.Callable(passlib.hash.sha256_crypt.encrypt,
|
|
|
|
salt_size=16,
|
|
|
|
rounds=10000)
|
|
|
|
password_verifier = di.Callable(passlib.hash.sha256_crypt.verify)
|
2015-07-15 21:49:20 +00:00
|
|
|
|
2015-10-22 13:51:16 +00:00
|
|
|
# Making some asserts:
|
2015-07-15 23:39:21 +00:00
|
|
|
hashed_password = password_hasher('super secret')
|
|
|
|
assert password_verifier('super secret', hashed_password)
|