Coverage for app/ddd/infrastructure/service/auth_service_impl.py: 100%
4 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-15 01:44 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-15 01:44 +0000
1import bcrypt
3from app.ddd.domain.error import UserAuthError
4from app.ddd.domain.service import AuthService
7class AuthServiceImpl(AuthService):
8 def verify_password(self, plain_password: str, hashed_password: str) -> bool:
9 """hashed_passerdの確認."""
10 result = bcrypt.checkpw(plain_password.encode(), hashed_password.encode())
11 if result is False:
12 raise UserAuthError
13 return result
15 def create_hashed_password(self, plain_password: str) -> str:
16 """hashed_passerdの作成."""
17 salt = bcrypt.gensalt(rounds=12, prefix=b"2a")
18 return bcrypt.hashpw(plain_password.encode(), salt).decode()