Professional Documents
Culture Documents
ASSIGNMENT-3
JSP APPLICATION
Page 1 of 19
index.jsp
<%--
Document : index
Author : siddarth
--%>
Page 2 of 19
<!DOCTYPE html>
<html>
<head>
<title>Bank Application</title>
</head>
<body>
<h1>BANK LOGIN</h1>
Integer count=(Integer)session.getAttribute("attemptcount");
if (count == null)
count=new Integer(1);
else
session.setAttribute("attemptcount",count);
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bank","root","4200");
PreparedStatement stmt=con.prepareStatement(sql);
stmt.setString(1,username);
stmt.setString(2,password);
ResultSet rs=stmt.executeQuery();
if(rs.next()){
Page 3 of 19
con.close();
session.setAttribute("twofactor",otp);
session.setAttribute("username",username);
session.removeAttribute("attemptcount");
response.sendRedirect("authentication.jsp");
else{
if(count<3){
else if(count==3){
else
tomorrow.</h2>");
con.close();
catch (Exception e) {
Page 4 of 19
%>
<label for="username">Username:</label><br>
<label for="password">Password:</label><br>
</form><br>
</body>
</html>
register.jsp
<%--
Document : register
Author : siddarth
--%>
<!DOCTYPE html>
<html>
<head>
<title>Registration</title>
</head>
Page 5 of 19
<body>
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bank","root","4200");
PreparedStatement stmt=con.prepareStatement(sql);
stmt.setString(1,accno);
stmt.setString(2,accname);
stmt.setString(3,acctype);
stmt.setString(4,branch);
stmt.setString(5,city);
stmt.setString(6,mobile);
stmt.executeUpdate();
con.close();
catch (Exception e) {
out.println("<h1>Registration Failed"+e.getMessage()+"</h1>");
Page 6 of 19
session.setAttribute("accountnum",accno);
response.sendRedirect("createCredentials.jsp");
%>
<option value="Savings">Savings</option>
<option value="Current">Current</option>
<option value="Salary">Salary</option>
<option value="NRI">NRI</option>
</select><br><br>
<label for="branch">Branch:</label>
<label for="city">City:</label>
9]{9}" required><br><br>
</form>
Page 7 of 19
</body>
</html>
authentication.jsp
<%--
Document : authentication
Author : siddarth
--%>
<!DOCTYPE html>
<html>
<head>
<title>Authentication</title>
</head>
<body>
<h1>Two-Factor Authentication</h1>
out.println("<h2>OTP: "+otp+"</h2>");
if(onetime.equals(otp.toString())){
session.removeAttribute("twofactor");
response.sendRedirect("displayProfile.jsp");
Page 8 of 19
else{
%>
</form>
</body>
</html>
displayProfile.jsp
<%--
Document : displayProfile
Author : siddarth
--%>
<!DOCTYPE html>
<html>
<head>
Page 9 of 19
<title>Profile</title>
</head>
<body>
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bank","root","4200");
PreparedStatement stmt=con.prepareStatement(sql);
stmt.setString(1,username);
ResultSet rs=stmt.executeQuery();
while(rs.next()){
String accno=rs.getString("accno");
String accname=rs.getString("accname");
String acctype=rs.getString("acctype");
String branch=rs.getString("branch");
String city=rs.getString("city");
String mob=rs.getString("mobile");
out.println("<tr><th>Account
Number</th><td>"+accno+"</td></tr><tr><th>Account
Name:</th><td>"+accname+"</td></tr>");
out.println("<tr><th>Account
Page 10 of 19
Type</th><td>"+acctype+"</td></tr><tr><th>Branch</th><td>"+branch+"</td></tr>");
out.println("<tr><th>City</th><td>"+city+"</td></tr><tr><th>Mobile</th><td>"+mob+"</td><
/tr
>");
out.println("</table>");
catch (Exception e) {
%>
<br>
</body>
</html>
createCredentials.jsp
<%--
Document : createCredentials
Author : siddarth
--%>
<!DOCTYPE html>
Page 11 of 19
<html>
<head>
<title>Create Username</title>
</head>
<body>
try{
Class.forName("com.mysql.cj.jdbc.Driver");
Connection
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/bank","root","4200");
PreparedStatement stmt=con.prepareStatement(sql);
stmt.setString(1,nuname);
stmt.setString(2,npsswd);
stmt.setString(3,accno);
stmt.executeUpdate();
con.close();
catch (Exception e) {
out.println("<h1>Registration Failed"+e.getMessage()+"</h1>");
session.removeAttribute("accountnum");
response.sendRedirect("index.jsp");
Page 12 of 19
}
%>
</form>
</body>
</html>
Login Page
Page 13 of 19
Account Creation Page
Page 14 of 19
Username and Password Creation Page
Page 15 of 19
Two-Factor Authentication Page
Page 16 of 19
Account Details
Wrong Attempts
Page 17 of 19
Page 18 of 19
Database
******************
Page 19 of 19