hi

can any one help me in this.. i have a html/jsp form in that i have a field .. enter password... first time password will be stored in the databse... from second time when user enters passowrd wrongly for 3 times then it has to dispay some msg contact ur administrator. can any one send me this code? plzzzzzzzzzzzzzzzz send it ASAp


Thanks&Regards
Mahaboob Basha

Have a variable that counts how many times the password has been entered.
When the password is wrong increase its value and put its value to a hidden field so to get it at request when the form is submitted again the next time.

can any one send me this code? plzzzzzzzzzzzzzzzz send it ASAp

Yeah, sure the code is already available here

Have a variable that counts how many times the password has been entered.
When the password is wrong increase its value and put its value to a hidden field so to get it at request when the form is submitted again the next time.

Hi

Thanks for sending this i would feel happy if u send me the piece of java code as iam new to this java coding..

If you have already a page that does the login and the inserts to the database,
then you are familiar with writing HTML, submiting forms, and getting the parameters from the request.

If you have written nothing and you expect to get the entire code, you won't. If you are new to java then this is not for you, because this isn't just basic java.

It will require something more than a few lines of java code for anyone to send. We will need to see your code and what you have written, in order to understand what kind of changes are required in YOUR code and where to put them

import java.io.*;
import java.util.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

 public class Validation extends HttpServlet
  {
  private ServletConfig config;
      public void init(ServletConfig config)throws ServletException
      {
       this.config=config;
      }

  public void service(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException 
   {  
    String   userName   = request.getParameter("user"); 
    String   password   = request.getParameter("pass"); 
    PrintWriter out     =response.getWriter();
    HttpSession session = request.getSession();

    boolean login(String userName, String password) 
      {
      try {
      Class.forName("com.mysql.jdbc.Driver"); 
      Connection con =DriverManager.getConnection("jdbc:mysql://localhost/basha","root","3ptec"); 
      Statement s = con.createStatement(); 
      String sql = "SELECT user FROM user" + 
        " WHERE user='" + user + "'" + 
        " AND Password='" + password + "'"; 
      ResultSet rs = s.executeQuery(sql); 
      if (rs.next())
          {
        rs.close(); 
        s.close(); 
        con.close(); 
        return true; 
          } 
        rs.close(); 
        s.close(); 
        con.close(); 
          } 

       if(userName.equals(request.getParameter("user"))&& password.equals(request.getParameter("pass")))
        {
        out.println("<h1>User is Valid</h1>");
       }
        else
        {
       out.println("<h1>User is InValid</h1>");
        }

        if (!login(username, password) ) 
               {
		int count = Integer.parseInt( session.getAttribute("count") );
		if (count > 3) {
			response.sendRedirect("badbadUser.jsp");
		 }
		else {
			count++;
			session.setAttribute("count");
			response.sendRedirect("woopsWrongPasswordTryAgain.jsp");
		}

    catch (ClassNotFoundException e) 
     {
      System.out.println(e.toString()); 
    } 
    catch (SQLException e) {
      System.out.println(e.toString()); 
    } 
    catch (Exception e) {
      System.out.println(e.toString()); 
    } 
    return false; 
    }
}
  

    
    
}  	
}

create jsp login page and validate username and password database to check the username and password is wrong to display error message or correct the go to next page

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.