주니어 개발자가 되는 중입니다...loading....
13. Spring : 비밀번호 암호화 처리 본문
1. pom.xml에 암호화 라이브러리 추가하기 후 버전 ${org.springframework-version} 으로 맞춰주기
https://mvnrepository.com/artifact/org.springframework.security/spring-security-core
https://mvnrepository.com/artifact/org.springframework.security/spring-security-web
https://mvnrepository.com/artifact/org.springframework.security/spring-security-config/6.0.1
2. security-context.xml 파일 생성
: WEB-INF > spring 우클릭 > other > spring bean definition file > beans, security 추가해주기 > finish
[BCryptPasswordEncoder] 클래스 이용
3. controller
this.passwoedEncoder=passwoedEncoder; 넣어주기
- enrollMemberEnd메소드에 로직 추가해주기
String encodePassword=passwordEncoder.encode(m.getPassword());
m.setPassword(encodePassword);
4. 암호화 완성! 회원가입후 DB에서 비밀번호 암호화 되어있는 지 확인
5. 같은 1234라는 비밀번호로 설정해도 암호화는 다르게 된다
6. But!! 암호화로된 DB에 저장된 비밀번호와 로그인시 입력하는 비밀번호 값과 동등비교를 해야한다...!
- 암호화된 패스워드를 원본값이랑 비교하기 위해서는 BCryptPasswordEncode 클래스가 제공하는 메소드를 이용해서 동등비교를 해야한다
- matched("원본값",암호화값)매소드를 이용
'Spring 스프링' 카테고리의 다른 글
15. Spring : log란? (0) | 2023.01.09 |
---|---|
14. Spring : Model로 로그인 성공시키기(HttpSession없이) (0) | 2023.01.06 |
12. Spring : 로그인, 로그아웃, 회원가입,내정보보기구현하기 (0) | 2023.01.06 |
10. Spring 서블릿처럼 사용해보기 (3) : DB연결하기 (0) | 2023.01.05 |
+)spring의 구조구조구조!! (0) | 2023.01.05 |