2020-09-02 01:39:23 +00:00
|
|
|
"""`Callable` provider example."""
|
|
|
|
|
|
|
|
import passlib.hash
|
|
|
|
|
2020-09-03 20:57:35 +00:00
|
|
|
from dependency_injector import containers, providers
|
2020-09-02 01:39:23 +00:00
|
|
|
|
|
|
|
|
2020-09-03 20:57:35 +00:00
|
|
|
class Container(containers.DeclarativeContainer):
|
|
|
|
|
|
|
|
password_hasher = providers.Callable(
|
|
|
|
passlib.hash.sha256_crypt.hash,
|
|
|
|
salt_size=16,
|
|
|
|
rounds=10000,
|
|
|
|
)
|
|
|
|
|
|
|
|
password_verifier = providers.Callable(passlib.hash.sha256_crypt.verify)
|
2020-09-02 01:39:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-09-03 20:57:35 +00:00
|
|
|
container = Container()
|
|
|
|
|
|
|
|
hashed_password = container.password_hasher('super secret')
|
|
|
|
assert container.password_verifier('super secret', hashed_password)
|