Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2004
    Posts
    10

    Unanswered: prob.. in login page

    hi..all of u....

    i have made a login page in html page...in which two text field there..named username and password...

    i want to do the stuff that if the user enter correct username and password..then it displays a pop up window mentioning that u have successfully enetered and it then directly went into the mypage.jsp page...(targeted page)

    and if users enter wrong entry then it displays error in another page..

    plz... do the needful for me....i am not getting any thing....

    my code is as follow:


    try
    {

    String Username = request.getParameter("msno");
    String Password = request.getParameter("pass");

    sql = conn.prepareStatement("SELECT * FROM login_mast WHERE name = '" + Username + "' and password='"+Password+"' ");

    results = sql.executeQuery();

    while(results.next())
    {

    String Dbname = results.getString("name");
    String Dbpassword = results.getString("password");


    out.println("<TABLE >");
    out.println("<TR>");
    out.println("<TD><strong>Username</strong>:</TD>");
    out.println("<TD><strong>Password</strong>:</TD></TR>");

    out.println("<tr><td> <INPUT TYPE='TEXT' size='5' value='" + Dbname + "' readonly </td>");
    out.println("<td> <INPUT TYPE='TEXT' size='5' value='" + Dbpassword + "' readonly </td></tr>");
    }
    }
    catch (SQLException s)

  2. #2
    Join Date
    Feb 2005
    Posts
    10

    Here is one solution

    1. Create a html page with your login tenplate, to take userid and password.
    form action should go to a .jsp page ( Say checkLogin.jsp)
    2. Write the validation code in checkLogin.jsp what ever the code.
    select username from your usertable where password = ? and username = ?
    3. If the validation is correct send him to the succesful welcome page.( you can use 2 directives) Page redirect and forward.
    4. to get the popup write a javascript on Onload on the welcome page.
    5. write the what ever lines in popup.html.

    Hope this helps.

    vijay

  3. #3
    Join Date
    Dec 2004
    Posts
    10
    hey i have used this like that..but when ever i make correct entry its send to error page...

    whats the prob...
    <%
    try
    {

    String Username = request.getParameter("msno");
    String Password = request.getParameter("pass");

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbcdbcf","scott","ttlscott");

    PreparedStatement sql = con.prepareStatement("SELECT * FROM login_mast WHERE name = '" + Username + "' and password='"+Password+"' ");

    ResultSet results = sql.executeQuery();

    String Dbpassword=results.getString("password");

    if(Password.equals(Dbpassword))

    {

    out.println("correct");

    }else{
    out.println("wrong");

    }
    }
    catch (SQLException s)

    {
    out.println(s.getMessage ());
    }


    %>

  4. #4
    Join Date
    Feb 2005
    Posts
    10

    dont

    Do not compare again with you password,
    You will get the resultset only when your username and password matches from the database( Means if he is the valid user )
    If you have resultset , user is valid. If you get nothing or error Login is not valid.

    Vijay B

  5. #5
    Join Date
    Feb 2005
    Location
    Sweden
    Posts
    45

    Talking Try this one.

    This will check if the user exists or not and then check the users password.
    <%
    try{

    String Username = request.getParameter("msno");
    String Password = request.getParameter("pass");

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con=DriverManager.getConnection("jdbcdbcf","scott" ,"ttlscott");

    PreparedStatement sql = con.prepareStatement("SELECT password FROM login_mast WHERE name = '" + Username + "'");

    ResultSet results = sql.executeQuery();

    if(result.first()){
    if(result.getString("password").equals(Password)){
    //case when login is correct.
    }else{
    //Case when the password is incorrect!
    }
    }else{
    //Case when the user don't exists.
    }
    }catch (SQLException s){
    out.println(s.getMessage ());
    }

    %>
    Last edited by ManhQuynh; 02-25-05 at 21:44.

Posting Permissions

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