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

19 lines
674 B
Python
Raw Normal View History

2015-07-16 02:39:21 +03:00
"""`Callable` providers example."""
from passlib.hash import sha256_crypt
2015-08-31 16:31:38 +03:00
from dependency_injector.providers import Callable
from dependency_injector.injections import KwArg
2015-07-16 02:39:21 +03: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 = Callable(sha256_crypt.encrypt,
KwArg('salt_size', 16),
KwArg('rounds', 10000))
password_verifier = Callable(sha256_crypt.verify)
2015-07-16 02:39:21 +03:00
# Making some asserts (client's code):
hashed_password = password_hasher('super secret')
assert password_verifier('super secret', hashed_password)