Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2008
    Posts
    11
    Rep Power
    0

    Default how to check password for 3 times enterd wrong password

    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


    here is my code

    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;
    }
    }




    }
    }

  2. #2
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Exclamation use String Hash Code

    At least this is posted in correct forum, passwords from 30,000 meters ( ! ) maybe we should check for ice on the wings or something...

    boolean BooLeen =false; String sting = ServletRequest.getParameter("passoword in the clear");if(collection.contains(sting.hashCode())){ doLogin();}else{BooLeen = checkCounter(sting.hashCode());}if(Booleen){...... } and so on.

    I hope this is a student project and there are no valuable data floating around.....needful to use java.security or javax.crypto ( HMAC or something )
    Introduction to Programming Using Java.
    Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

  3. #3
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    You can make a hidden div in jsp file,then in Servlet (if your framework is Spring) create a ModelAndView object,then if the password was failed,add the object to it as a String with fail info and the number of times it was failed,and redirect again to your jsp page.Between the hidden div check if the password was failed,return the ModelAndView objects in the div message.Then if it failed three times update it in database,and don't let the servlet to go through those actions.If you don't use Spring,u can use HttpSession.

Similar Threads

  1. how to check password for 3 times enterd wrong password
    By sk.mahaboobbhasha@gmail.c in forum Java Servlet
    Replies: 0
    Last Post: 11-14-2008, 01:22 PM
  2. password ?!
    By jon80 in forum New To Java
    Replies: 9
    Last Post: 11-14-2008, 01:19 PM
  3. How to check password of a jsp/html with the password of Database(mysql) #1
    By sk.mahaboobbhasha@gmail.c in forum Java Servlet
    Replies: 2
    Last Post: 11-14-2008, 01:11 PM
  4. How to get password in SWT
    By Java Tip in forum SWT
    Replies: 0
    Last Post: 07-02-2008, 08:04 PM
  5. Asking for password from a Servlet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-27-2008, 08:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •