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

    Default How to check password of a jsp/html with the password of Database(mysql) #1

    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

  2. #2
    Md Saim is offline Member
    Join Date
    Sep 2008
    Location
    Kolkata, India
    Posts
    20
    Rep Power
    0

    Default

    hi
    follow this

    <%@ page language="java" import="java.sql.*" pageEncoding="UTF-8"%>
    <%
    String username=(String) request.getParameter("username ");
    String password=(String) request.getParameter("password ");
    Class.forName("com.mysql.jdbc.Driver");
    String url="jdbc:mysql://localhost:3306/dbName?user=root&password=acc";// JDBC URL
    Connection conn=DriverManager.getConnection(url);
    Statement stmt=conn.createStatement();
    String sql="SELECT * FROM member WHERE username='"+username+"' and password='"+password+"'";
    ResultSet rs=stmt.executeQuery(sql);
    boolean isCheck=false;
    if(rs.next()){
    isCheck=true;
    }
    %>

  3. #3
    Join Date
    Nov 2008
    Posts
    11
    Rep Power
    0

    Default

    whats wrong with this 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;
    }
    }




    }
    }

Similar Threads

  1. password ?!
    By jon80 in forum New To Java
    Replies: 9
    Last Post: 11-14-2008, 02:19 PM
  2. Password Dailog
    By Sarinam in forum New To Java
    Replies: 11
    Last Post: 07-19-2008, 09:37 PM
  3. How to get password in SWT
    By Java Tip in forum SWT Tips
    Replies: 0
    Last Post: 07-02-2008, 09:04 PM
  4. Password System help
    By quickfingers in forum New To Java
    Replies: 1
    Last Post: 06-23-2008, 07:18 PM
  5. Help with password matches
    By Albert in forum AWT / Swing
    Replies: 1
    Last Post: 07-10-2007, 05:17 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
  •