[Spring][쇼핑몰 프로젝트][9] 비밀번호 인코딩(BCryptPasswordEncoder 적용) - 1
https://kimvampa.tistory.com/132?category=771727
This commit is contained in:
@@ -205,6 +205,26 @@
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- security -->
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-core</artifactId>
|
||||
<version>5.4.2</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-web</artifactId>
|
||||
<version>5.4.2</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-config -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-config</artifactId>
|
||||
<version>5.4.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@@ -32,6 +33,9 @@ public class MemberController {
|
||||
@Autowired
|
||||
private JavaMailSender mailSender;
|
||||
|
||||
@Autowired
|
||||
private BCryptPasswordEncoder pwEncoder;
|
||||
|
||||
//회원가입 페이지 이동
|
||||
@RequestMapping(value="/join", method=RequestMethod.GET)
|
||||
public void loginGET() {
|
||||
@@ -44,13 +48,16 @@ public class MemberController {
|
||||
@RequestMapping(value="/join", method=RequestMethod.POST)
|
||||
public String joinPOST(MemberVO member) throws Exception{
|
||||
|
||||
logger.info("join 진입");
|
||||
String rawPw = ""; // 인코딩 전 비밀번호
|
||||
String encodePw = ""; // 인코딩 후 비밀번호
|
||||
|
||||
// 회원가입 서비스 실행
|
||||
rawPw = member.getMemberPw(); // 비밀번호 데이터 얻음
|
||||
encodePw = pwEncoder.encode(rawPw); // 비밀번호 인코딩
|
||||
member.setMemberPw(encodePw); // 인코딩된 비밀번호 member객체에 다시 저장
|
||||
|
||||
/* 회원가입 쿼리 실행 */
|
||||
memberservice.memberJoin(member);
|
||||
|
||||
logger.info("join Service 성공");
|
||||
|
||||
return "redirect:/main";
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:security="http://www.springframework.org/schema/security"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
|
||||
|
||||
<bean id="bcryptPasswordEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"></bean>
|
||||
|
||||
</beans>
|
||||
@@ -20,7 +20,10 @@
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
|
||||
<param-value>
|
||||
/WEB-INF/spring/appServlet/servlet-context.xml
|
||||
/WEB-INF/spring/appServlet/security-context.xml
|
||||
</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#Generated by Maven Integration for Eclipse
|
||||
#Tue Jan 19 18:15:49 KST 2021
|
||||
#Wed Jan 20 01:28:43 KST 2021
|
||||
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project\\VamPa
|
||||
m2e.projectName=VamPa
|
||||
groupId=com.vam
|
||||
|
||||
@@ -205,6 +205,26 @@
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- security -->
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-core</artifactId>
|
||||
<version>5.4.2</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-web</artifactId>
|
||||
<version>5.4.2</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-config -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-config</artifactId>
|
||||
<version>5.4.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
|
||||
@@ -205,6 +205,26 @@
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- security -->
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-core</artifactId>
|
||||
<version>5.4.2</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-web</artifactId>
|
||||
<version>5.4.2</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-config -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-config</artifactId>
|
||||
<version>5.4.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
@@ -32,6 +33,9 @@ public class MemberController {
|
||||
@Autowired
|
||||
private JavaMailSender mailSender;
|
||||
|
||||
@Autowired
|
||||
private BCryptPasswordEncoder pwEncoder;
|
||||
|
||||
//회원가입 페이지 이동
|
||||
@RequestMapping(value="/join", method=RequestMethod.GET)
|
||||
public void loginGET() {
|
||||
@@ -44,13 +48,16 @@ public class MemberController {
|
||||
@RequestMapping(value="/join", method=RequestMethod.POST)
|
||||
public String joinPOST(MemberVO member) throws Exception{
|
||||
|
||||
logger.info("join 진입");
|
||||
String rawPw = ""; // 인코딩 전 비밀번호
|
||||
String encodePw = ""; // 인코딩 후 비밀번호
|
||||
|
||||
// 회원가입 서비스 실행
|
||||
rawPw = member.getMemberPw(); // 비밀번호 데이터 얻음
|
||||
encodePw = pwEncoder.encode(rawPw); // 비밀번호 인코딩
|
||||
member.setMemberPw(encodePw); // 인코딩된 비밀번호 member객체에 다시 저장
|
||||
|
||||
/* 회원가입 쿼리 실행 */
|
||||
memberservice.memberJoin(member);
|
||||
|
||||
logger.info("join Service 성공");
|
||||
|
||||
|
||||
return "redirect:/main";
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:security="http://www.springframework.org/schema/security"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
|
||||
|
||||
<bean id="bcryptPasswordEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"></bean>
|
||||
|
||||
</beans>
|
||||
@@ -20,7 +20,10 @@
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
|
||||
<param-value>
|
||||
/WEB-INF/spring/appServlet/servlet-context.xml
|
||||
/WEB-INF/spring/appServlet/security-context.xml
|
||||
</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#Generated by Maven Integration for Eclipse
|
||||
#Tue Jan 19 22:10:01 KST 2021
|
||||
#Wed Jan 20 01:29:06 KST 2021
|
||||
m2e.projectLocation=C\:\\Users\\sjinj\\git\\Blog_Project\\VamPa_MySQL
|
||||
m2e.projectName=VamPa_MySQL
|
||||
groupId=com.vam
|
||||
|
||||
@@ -205,6 +205,26 @@
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- security -->
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-core</artifactId>
|
||||
<version>5.4.2</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-web -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-web</artifactId>
|
||||
<version>5.4.2</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-config -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-config</artifactId>
|
||||
<version>5.4.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Test -->
|
||||
<dependency>
|
||||
|
||||
Reference in New Issue
Block a user