-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFindPwOk.jsp
More file actions
64 lines (54 loc) · 2.26 KB
/
FindPwOk.jsp
File metadata and controls
64 lines (54 loc) · 2.26 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<%@page import="java.sql.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>비밀번호 재설정 완료</title>
</head>
<body style="display: flex; justify-content: center; margin: 0px;">
<%
request.setCharacterEncoding("UTF-8");
String userId = request.getParameter("userId");
String name = request.getParameter("name");
String phone = request.getParameter("phone");
String password = request.getParameter("password");
try{
String DB_URL = "jdbc:mysql://localhost:3306/internetproject"; // 접속할 DB명
String DB_ID = "multi"; // 접속할 아이디
String DB_PASSWORD = "abcd"; // 접속할 패스워드
Class.forName("com.mysql.jdbc.Driver"); // JDBC 드라이버 로딩
Connection con = DriverManager.getConnection(DB_URL, DB_ID, DB_PASSWORD); // DB에 접속
String sql = "SELECT * FROM user WHERE userId = ? AND name = ? AND phone = ?"; //SQL문 작성
//PreparedStatement 생성(SQL문의 형틀을 정의)
PreparedStatement pstmt = con.prepareStatement(sql);
pstmt.setString(1, userId);
pstmt.setString(2, name);
pstmt.setString(3, phone);
// sql문 실행
pstmt.executeQuery();
String sql2 = "UPDATE user SET password = ? WHERE userId = ? AND name = ? AND phone = ?";
PreparedStatement pstmt2 = con.prepareStatement(sql2);
pstmt2.setString(1, password);
pstmt2.setString(2, userId);
pstmt2.setString(3, name);
pstmt2.setString(4, phone);
int result = pstmt2.executeUpdate();
if(result == 1){ // 성공 %>
<script>
alert("비밀번호 재설정에 성공하였습니다.");
window.location.href = "<%= request.getContextPath() %>/Login.jsp";
</script>
<% } else{ // 실패 %>
<script>
alert("비밀번호 재설정에 실패하였습니다");
window.location.href = "<%= request.getContextPath() %>/FindUser.jsp";
</script>
<% }
}catch(Exception e){
out.println(e);
}
%>
</body>
</html>