Skip to content

Commit 5bf8793

Browse files
committed
[FEAT] 비밀번호 복호화 과정 진행
1 parent 06b9689 commit 5bf8793

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/main/java/com/example/be/config/SecurityConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
1111
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
1212
import org.springframework.security.config.annotation.web.configurers.HttpBasicConfigurer;
13+
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
14+
import org.springframework.security.crypto.password.PasswordEncoder;
1315
import org.springframework.security.web.SecurityFilterChain;
1416
import org.springframework.web.cors.CorsConfiguration;
1517
import org.springframework.web.cors.CorsConfigurationSource;
@@ -26,6 +28,11 @@ public class SecurityConfig {
2628
private final OAuthLoginSuccessHandler oAuthLoginSuccessHandler;
2729
private final OAuthLoginFailureHandler oAuthLoginFailureHandler;
2830

31+
@Bean
32+
public PasswordEncoder passwordEncoder() {
33+
return new BCryptPasswordEncoder();
34+
}
35+
2936
@Bean
3037
CorsConfigurationSource corsConfigurationSource() {
3138
CorsConfiguration config = new CorsConfiguration();

src/main/java/com/example/be/service/UserServiceImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import lombok.extern.slf4j.Slf4j;
1616
import org.springframework.beans.factory.annotation.Value;
1717
import org.springframework.scheduling.annotation.Scheduled;
18+
import org.springframework.security.crypto.password.PasswordEncoder;
1819
import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler;
1920
import org.springframework.stereotype.Service;
2021
import org.springframework.transaction.annotation.Transactional;
@@ -31,6 +32,7 @@ public class UserServiceImpl extends SimpleUrlAuthenticationSuccessHandler {
3132
private final UserRepository userRepository;
3233
private final JwtUtilServiceImpl jwtUtilService;
3334
private final RefreshTokenRepository refreshTokenRepository;
35+
private final PasswordEncoder passwordEncoder;
3436

3537
@Value("${jwt.access-token.expiration-time}")
3638
private long ACCESS_TOKEN_EXPIRATION_TIME; // 액세스 토큰 유효기간
@@ -59,7 +61,7 @@ public CommonDTO.IsSuccessDTO signUp(UserDTO.SingUpRequestDto request) {
5961

6062
User user = User.builder()
6163
.email(request.getEmail())
62-
.password(request.getPassword())
64+
.password(passwordEncoder.encode(request.getPassword()))
6365
.name(request.getName())
6466
.userId(UUID.randomUUID())
6567
.provider("general")
@@ -82,7 +84,7 @@ public CommonDTO.IsSuccessDTO login(UserDTO.LoginRequestDto request, HttpServlet
8284
User user = userRepository.findByEmail(request.getEmail()).orElseThrow(()
8385
-> new UserHandler(ErrorStatus._NOT_FOUND_USER));
8486

85-
if (!user.getPassword().equals(request.getPassword()))
87+
if (!passwordEncoder.matches(request.getPassword(), user.getPassword()))
8688
throw new UserHandler(ErrorStatus._NOT_CORRECT_PASSWORD);
8789

8890
refreshTokenRepository.deleteByUserId(user.getUserId());

0 commit comments

Comments
 (0)