-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
22 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/com/kakao/golajuma/auth/domain/helper/Encoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.kakao.golajuma.auth.domain.helper; | ||
|
||
import org.mindrot.jbcrypt.BCrypt; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class Encoder { | ||
public String encode(String raw) { | ||
return BCrypt.hashpw(raw, BCrypt.gensalt()); | ||
} | ||
|
||
public boolean matches(String raw, String hashed) { | ||
return BCrypt.checkpw(raw, hashed); | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
src/main/java/com/kakao/golajuma/auth/infra/converter/UserEntityConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
package com.kakao.golajuma.auth.infra.converter; | ||
|
||
import com.kakao.golajuma.auth.domain.helper.Encoder; | ||
import com.kakao.golajuma.auth.infra.entity.UserEntity; | ||
import com.kakao.golajuma.auth.web.dto.request.SaveUserRequest; | ||
import com.kakao.golajuma.common.support.converter.AbstractEntityConverter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class UserEntityConverter implements AbstractEntityConverter<UserEntity, SaveUserRequest> { | ||
|
||
private final PasswordEncoder passwordEncoder; | ||
private final Encoder encoder; | ||
|
||
@Override | ||
public UserEntity toEntity(SaveUserRequest source) { | ||
return UserEntity.builder() | ||
.nickname(source.getNickname()) | ||
.email(source.getEmail()) | ||
.password(passwordEncoder.encode(source.getPassword())) | ||
.password(encoder.encode(source.getPassword())) | ||
.build(); | ||
} | ||
} |