when user try to login that time only 3 try available for login.
if user attempt invalid login then that user automatically block,and they cant login on this website.
authenticate.java
package com.authenticate;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.connection.DBConnection;
/**
* Servlet implementation class Login
*/
@WebServlet("/Login")
public class Login extends HttpServlet {
private static final long serialVersionUID = 1L;
int login_attempts = 3;
/**
* @see HttpServlet#HttpServlet()
*/
public Login() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String email = request.getParameter("email");
String pass = request.getParameter("password");
try{
Connection con = DBConnection.getConnection();
PreparedStatement ps =con.prepareStatement
("select * from user where mail=? and password=? and account_lock=0 ");
ps.setString(1, email);
ps.setString(2, pass);
ResultSet rs =ps.executeQuery();
if(rs.next())
{
String userdbName = rs.getString("user_name");
String customer_id = rs.getString("customer_id");
/*String account_status = rs.getString("account_lock");
int bool1 = Integer.parseInt(account_status);
*/
HttpSession session=request.getSession();
session.setAttribute("name",userdbName);
session.setAttribute("cid",customer_id);
response.sendRedirect("personal/home.jsp");
}
else{
{
if(login_attempts==0)
{
System.out.println("No Login Attempts Available");
}
else
{
login_attempts=login_attempts-1;
System.out.println("Login Failed Now Only "+login_attempts+" Login Attempts Available");
if(login_attempts==0)
{
System.out.println("your account block.contact admin for login.");
}
}
}
response.sendRedirect("login.jsp");
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
0 Comments