This repository has been archived by the owner on Oct 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
forgotPass.jsp
85 lines (83 loc) · 3.01 KB
/
forgotPass.jsp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<%@page import="java.util.UUID"%>
<%@page import="com.sun.mail.smtp.SMTPTransport"%>
<%@page import="javax.mail.internet.MimeMessage"%>
<%@page import="javax.mail.internet.InternetAddress"%>
<%@page import="javax.mail.Message"%>
<%@page import="javax.mail.Session"%>
<%@page import="java.util.Properties"%>
<%@page import="java.util.Random"%>
<%@page import="java.util.Date"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ include file="jspConfig.jsp" %>
<%@ include file="mail.jsp" %>
<%
try {
if(request.getParameter("user") != null)
{
String alert ="";
String user = request.getParameter("user");
String to = user + "@cit.ac.in";
Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager.getConnection(mysqlURL,mysqlUser,mysqlPass);
PreparedStatement ps1;
ResultSet rs;
ps1 = conn.prepareStatement("select * from student where email = ? and verified = 1");
ps1.setString(1, user);
rs = ps1.executeQuery();
if(rs.next())
{
final String uid = UUID.randomUUID().toString().replace("-", "");
Date ct = new Date();
long time = ct.getTime();
//System.out.println(uid + " " + time);
String subject = "[Hostel Feedback System] Password Reset";
String msg = "Someone (hopefully you) requested for a password reset. Please click the link below to verify yourself.\n";
msg += "http://" + mailRedirectURL + "/reset/?id=" + uid + "&user=" + user;
msg += "\n\nIf u can't click the link then copy the link in the address bar and then press enter.\n";
msg += "If u have not requested for registration then please disregard this mail and no action will be taken.\n\n";
msg += "Hostel Feedback System";
ps1 = conn.prepareStatement("update student set otp = ?, otpTime = ? where email = ?");
ps1.setString(1, uid);
ps1.setLong(2, time);
ps1.setString(3, user);
ps1.executeUpdate();
sendMail(to, subject, msg);
conn.close();
%>
<div class="alert alert-success alert-dismissible fade show" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
A password reset link was successfully send to your email. If u don't find the mail in your inbox then check it in your spam/junk folder.
</div>
<%
}
else
{
%>
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
The email entered is not found in our system.
</div>
<%
conn.close();
}
}
else
{
%>
<script>document.location = "/hostelFeedback/"</script>
<%
}
}
catch(Exception e) {
%>
<jsp:forward page="/error/"></jsp:forward>
<%
}
%>