"""Password hashing example."""

from typing import Callable, Dict

import passlib.hash

from dependency_injector import containers, providers


class UserService:

    def __init__(self, password_hasher: Callable[[str], str]) -> None:
        self._password_hasher = password_hasher

    def create_user(self, name: str, password: str) -> Dict[str, str]:
        hashed_password = self._password_hasher(password)
        return {
            'name': name,
            'password': hashed_password,
        }


class Container(containers.DeclarativeContainer):

    config = providers.Configuration()

    password_hasher = providers.Callable(
        passlib.hash.sha256_crypt.hash,
        salt_size=config.salt_size,
        rounds=config.rounds,
    )

    user_service = providers.Factory(
        UserService,
        password_hasher=password_hasher.provider,
    )


if __name__ == '__main__':
    container = Container(
        config={
            'salt_size': 16,
            'rounds': 10000,
        },
    )

    user_service = container.user_service()

    user = user_service.create_user(name='Roman', password='secret1')
    print(user)

@@ -440,14 +440,14 @@
     
-'
+%22
 name
-'
+%22
 : na
@@ -466,17 +466,17 @@
     
-'
+%22
 password
 ': h
@@ -471,17 +471,17 @@
 password
-'
+%22
 : hashed
@@ -885,17 +885,17 @@
  == 
-'
+%22
 __main__
 ':%0A 
@@ -890,17 +890,17 @@
 __main__
-'
+%22
 :%0A    co
@@ -949,17 +949,17 @@
         
-'
+%22
 salt_siz
@@ -959,17 +959,17 @@
 alt_size
-'
+%22
 : 16,%0A  
@@ -982,16 +982,16 @@
     
-'
+%22
 rounds
-'
+%22
 : 10
@@ -1103,15 +1103,15 @@
 ame=
-'
+%22
 Roman
-'
+%22
 , pa
@@ -1121,17 +1121,17 @@
 ord=
-'
+%22
 secret1
-'
+%22
 )%0A  

Update quotes in password-hashing example