개발/부트캠프

본캠프 : 비밀번호 암호화

EJ EJ 2025. 3. 7. 20:33

1. build.gradle - dependencies에 아래의 의존성을 추가

implementation 'at.favre.lib:bcrypt:0.10.2'

 

2. config 패키지에 PasswordEncoder 클래스 추가

@Component
public class PasswordEncoder {

    public String encode(String rawPassword) {
        return BCrypt.withDefaults().hashToString(BCrypt.MIN_COST, rawPassword.toCharArray());
    }

    public boolean matches(String rawPassword, String encodedPassword) {
        BCrypt.Result result = BCrypt.verifyer().verify(rawPassword.toCharArray(), encodedPassword);
        return result.verified;
    }
}

 

3. 처음 비밀번호를 저장(회원가입, 멤버 저장 등)하는 서비스 로직 수정

 

4. 로그인 서비스 로직 수정

 

끝!

 

[ 확인 ]