python-dependency-injector/examples/providers/callable_kwargs.py

17 lines
658 B
Python
Raw Normal View History

"""`Callable` providers with keyword arguments example."""
2015-09-02 15:48:11 +00:00
import passlib.hash
2016-06-06 08:54:05 +00:00
import dependency_injector.providers as providers
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):
password_hasher = providers.Callable(passlib.hash.sha256_crypt.encrypt,
salt_size=16,
rounds=10000)
password_verifier = providers.Callable(passlib.hash.sha256_crypt.verify)
# Making some asserts:
2015-07-15 23:39:21 +00:00
hashed_password = password_hasher('super secret')
assert password_verifier('super secret', hashed_password)