| 123456789101112131415161718192021222324252627282930313233 |
- using Application.Abstractions.Authentication;
- namespace Infrastructure.Authentication;
- // dpot 1.0 legacy 회원 비밀번호(bcrypt) 검증기. BCrypt.Net-Next 사용.
- // Domain은 외부 의존성 0 원칙이라 bcrypt 검증은 Infrastructure에 둔다.
- internal sealed class BcryptLegacyPasswordVerifier : ILegacyPasswordVerifier
- {
- public bool IsLegacyHash(string? hash)
- {
- if (string.IsNullOrEmpty(hash))
- {
- return false;
- }
- return hash.StartsWith("$2a$", StringComparison.Ordinal)
- || hash.StartsWith("$2b$", StringComparison.Ordinal)
- || hash.StartsWith("$2y$", StringComparison.Ordinal);
- }
- public bool Verify(string password, string legacyHash)
- {
- try
- {
- return BCrypt.Net.BCrypt.Verify(password, legacyHash);
- }
- catch
- {
- // 손상되었거나 형식이 맞지 않는 해시는 검증 실패로 처리
- return false;
- }
- }
- }
|