반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<!-- security 설정 -->
<!-- https://mvnrepository.com/artifact/org.springframework.security/spring-security-core -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>5.3.2.RELEASE</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.3.2.RELEASE</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.3.2.RELEASE</version>
</dependency>
|
cs |
pom.xml 에 security - web,core,config를 추가해줍니다.
전 가장 최신거 바로 밑에거로 했어요 오늘 기준(2020/06/20)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
@Controller
public class UserLoginController {
@Autowired
UserService userService;
@Autowired
BCryptPasswordEncoder encoder;
@RequestMapping("/page")
public String loginpage(HttpServletRequest request , HttpSession session, Model model) {
return "login/login";
}
@PostMapping("/login")
@ResponseBody
public Map<String,Object> login(HttpServletRequest request, HttpSession session)throws Exception{
String result = "F";
UserVO userInfo = null;
try {
// 아이디값을 넣어서 유저 정보를 가져옵니다.
Map<String,Object> map = new HashedMap<String, Object>();
map.put("user_id",request.getParameter("user_id"));
userInfo = userService.checkUser(map);
// 그 유저가 있으면
if(userInfo !=null) {
// 그 유저의 비밀번호와 넘어온 비밀번호를 비교해줍니다. encoder.matches 사용!
if(!encoder.matches(request.getParameter("user_pw"), userInfo.getUser_pw())) {
result="N";
throw new Exception("비밀번호가 틀렸다.");
}else {
result="S";
}
}else {
result="N";
throw new Exception("아이디가 틀렸다.");
}
}catch(Exception e) {
System.out.println(" 로그인 에러 : " +e);
}
Map<String,Object> resultJson = new HashedMap<String, Object>();
resultJson.put("result", result);
return resultJson;
}
}
|
cs |
반응형
'스프링 게시판' 카테고리의 다른 글
스프링게시판 만들기 리스트 , 페이지 나누기 (0) | 2021.01.12 |
---|---|
Spring json 데이터 통으로 받기 (0) | 2020.12.21 |
스프링 카카오 로그인 (0) | 2020.05.16 |
스프링 게시판 만들기 1 글쓰기 / 스프링 파일 업로드 / 스프링 다중파일 업로드/마이바티스 collection사용 (0) | 2020.04.26 |
스프링 설정 pom.xml / applicationContext.xml (database설정) /controller.xml (4) | 2020.04.26 |
댓글