From 9872405377d5773716892f2bd856b6ab0b9a656b Mon Sep 17 00:00:00 2001 From: s-choi Date: Fri, 25 Sep 2026 15:14:21 +0900 Subject: [PATCH] =?UTF-8?q?[EDIT]=20=E4=BC=9A=E5=93=A1=E7=99=BB=E9=8C=B2?= =?UTF-8?q?=E3=83=BB=E3=83=AD=E3=82=B0=E3=82=A4=E3=83=B3=E3=81=AB=E3=83=91?= =?UTF-8?q?=E3=82=B9=E3=83=AF=E3=83=BC=E3=83=89=E6=9A=97=E5=8F=B7=E5=8C=96?= =?UTF-8?q?=E6=A9=9F=E8=83=BD=E3=82=92=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=BE?= =?UTF-8?q?=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/service/impl/LoginServiceImpl.java | 30 ++++++++++++------- .../domain/service/impl/UserServiceImpl.java | 11 ++++--- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/example/demo/app/domain/service/impl/LoginServiceImpl.java b/src/main/java/com/example/demo/app/domain/service/impl/LoginServiceImpl.java index 9e1563a..2ec04b3 100644 --- a/src/main/java/com/example/demo/app/domain/service/impl/LoginServiceImpl.java +++ b/src/main/java/com/example/demo/app/domain/service/impl/LoginServiceImpl.java @@ -1,5 +1,6 @@ package com.example.demo.app.domain.service.impl; +import org.mindrot.jbcrypt.BCrypt; import org.springframework.stereotype.Service; import com.example.demo.app.domain.model.LoginModel; @@ -13,19 +14,26 @@ import lombok.RequiredArgsConstructor; @RequiredArgsConstructor public class LoginServiceImpl implements LoginService { - private final UserRepository userRepository; + private final UserRepository userRepository; - @Override - public LoginModel login(String mailAddress, String password) { + @Override + public LoginModel login(String mailAddress, String password) { - UserEntity userEntity = userRepository.findByMailAddressAndPassword( - mailAddress, - password).orElse(null); + UserEntity userEntity = userRepository + .findByMailAddress(mailAddress) + .orElse(null); - if (userEntity == null) { - return null; - } + if (userEntity == null) { + return null; + } + + boolean isValidPassword = BCrypt.checkpw(password, userEntity.getPassword()); + + if (!isValidPassword) { + return null; + } + + return new LoginModel(userEntity.getUserId()); + } - return new LoginModel(userEntity.getUserId()); - } } diff --git a/src/main/java/com/example/demo/app/domain/service/impl/UserServiceImpl.java b/src/main/java/com/example/demo/app/domain/service/impl/UserServiceImpl.java index 9cc6639..ed6c47f 100644 --- a/src/main/java/com/example/demo/app/domain/service/impl/UserServiceImpl.java +++ b/src/main/java/com/example/demo/app/domain/service/impl/UserServiceImpl.java @@ -1,5 +1,6 @@ package com.example.demo.app.domain.service.impl; +import org.mindrot.jbcrypt.BCrypt; import org.springframework.stereotype.Service; import com.example.demo.app.domain.model.UserModel; @@ -24,14 +25,17 @@ public class UserServiceImpl implements UserService { private final GoalRepository goalRepository; private final CourseRepository courseRepository; - @Override - public void register(UserForm userForm, Long courseId, Long userId) { + @Override + public void register(UserForm userForm, Long courseId) { UserEntity userEntity = new UserEntity(); userEntity.setUserName(userForm.getUserName()); userEntity.setMailAddress(userForm.getMailAddress()); - userEntity.setPassword(userForm.getPassword()); + + String passwordHashed = BCrypt.hashpw(userForm.getPassword(), BCrypt.gensalt()); + + userEntity.setPassword(passwordHashed); userEntity.setSecretQuestionAnswer(userForm.getSecretAnswer()); userEntity.setBirthDate(userForm.getBirthDate()); userEntity.setSaving(userForm.getSaving()); @@ -44,7 +48,6 @@ public class UserServiceImpl implements UserService { GoalEntity goalEntity = new GoalEntity(); goalEntity.setTargetAmount(Integer.parseInt(String.valueOf(userForm.getGoalId()))); - goalEntity.setUserEntity(userRepository.findById(userId).get()); CourseEntity courseEntity = courseRepository.findById(courseId).orElse(null);