-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.jsp
165 lines (123 loc) · 4.55 KB
/
index.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<%@ page import="java.sql.*" %>
<%
if(session.getAttribute("login")!=null) //check login session user not access or back to index.jsp page
{
response.sendRedirect("Live-Code-Editor.html");
}
%>
<%
try
{
Class.forName("com.mysql.jdbc.Driver"); //load driver
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/dbuser","root",""); //create connection
if(request.getParameter("btn_login")!=null) //check login button click event not null
{
String dbemail,dbpassword;
String email,password;
email=request.getParameter("txt_email"); //txt_email
password=request.getParameter("txt_password"); //txt_password
PreparedStatement pstmt=null; //create statement
pstmt=con.prepareStatement("select * from login where email=? AND password=?"); //sql select query
pstmt.setString(1,email);
pstmt.setString(2,password);
ResultSet rs=pstmt.executeQuery(); //execute query and store in resultset object rs.
if(rs.next())
{
dbemail=rs.getString("email");
dbpassword=rs.getString("password");
if(email.equals(dbemail) && password.equals(dbpassword))
{
session.setAttribute("login",dbemail); //session name is login and store fetchable database email address
response.sendRedirect("Live-Code-Editor.html"); //after login success redirect to Live-Code-Editor.html page
}
}
else
{
request.setAttribute("errorMsg","invalid email or password"); //invalid error message for email or password wrong
}
con.close(); //close connection
}
}
catch(Exception e)
{
out.println(e);
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Login</title>
<link rel="stylesheet" href="css/register.css">
<script>
function validate()
{
var email = document.myform.txt_email;
var password = document.myform.txt_password;
if (email.value == null || email.value == "") //check email textbox not blank
{
window.alert("please enter email ?"); //alert message
email.style.background = '#f08080';
email.focus();
return false;
}
if (password.value == null || password.value == "") //check password textbox not blank
{
window.alert("please enter password ?"); //alert message
password.style.background = '#f08080';
password.focus();
return false;
}
}
function myFunction() {
var x = document.getElementById("password");
if (x.type === "password") {
x.type = "text";
} else {
x.type = "password";
}
}
</script>
</head>
<body>
<div class="main-content">
<form class="form-register" method="post" name="myform" onsubmit="return validate();">
<div class="form-register-with-email">
<div class="form-white-background">
<div class="form-title-row">
<h1>Login</h1>
</div>
<p style="color:red">
<%
if(request.getAttribute("errorMsg")!=null)
{
out.println(request.getAttribute("errorMsg")); //error message for email or password
}
%>
</p>
</br>
<div class="form-row">
<label>
<span>Email</span>
<input type="text" name="txt_email" id="email" placeholder="Enter Email">
</label>
</div>
<div class="form-row">
<label>
<span>Password</span>
<input type="password" name="txt_password" id="password" placeholder="Enter Password"><br>
<input type="checkbox" onclick="myFunction()">Show Password
</label>
</div>
<input type="submit" name="btn_login" value="Login">   
<input type="reset" value="Reset"><br>
</div>
<br><a href="register.jsp" class="form-log-in-with-existing">New Here? <b>Wanna join us?</b></a><br>
<a href="index.html">Home</a>
</div>
</form>
</div>
</body>
</html>