Results 1 to 2 of 2

Thread: login page

  1. #1
    banie is offline Member
    Join Date
    Jan 2008
    Posts
    21
    Rep Power
    0

    Default login page

    Hi,

    I got problem with my login page. If i use wrong username, it will loop That account does not exist. Try again two times. If i use correct username, it also show it..

    This is my code:
    Java Code:
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@page language="java"  %>
    <html>
        <head>
            <title>Login Page</title>
        </head>
        <body>
         
    <%@page import="java.sql.*" %> 
    <%
    Connection con = null;
    try{
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    con = DriverManager.getConnection("jdbc:mysql://localhost:3306/sms","root","optimal3");
    
    
      
    Statement stm = null;
    ResultSet rs = null;
    
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    
    stm = con.createStatement();
    String query = "select username, password from account_user";
    rs = stm.executeQuery(query);
    %>
      <%
    while(rs.next())
    {
       String dbusername = rs.getString(1);
       String dbpassword = rs.getString(2);
    
    if(dbusername.equals(username) && dbpassword.equals(password))
      {
          out.println("You are logged in");
       }
    else 
      {
         out.println("That account does not exist. Try again.");
       }
    }
    %>
      <%
      }
       catch(SQLException ex){
    
    
    }
    %>
    Click <a href="sms.jsp">here</a> continue
    </body>
    </html>

  2. #2
    sagarbirari is offline Member
    Join Date
    Sep 2008
    Posts
    17
    Rep Power
    0

    Default

    Hello

    Why r u selecting whole user from database and then chk it for existing user,
    Instead of user following query which chk user name and pass of user with Database
    String query = "select * from account_user where username='"+username+"' and password='"+password+"'" ;

    and then if user exist it will return 1 row otherwise no row will be returned
    you can chk this condition
    if(rs.next())
    {
    //user exist code
    }
    else
    {
    // user not exidt code
    }


    Regards

Similar Threads

  1. Need to return to login page once logout
    By peiceonly in forum Suggestions & Feedback
    Replies: 2
    Last Post: 03-31-2009, 08:50 PM
  2. login page
    By keerthi_y19 in forum New To Java
    Replies: 9
    Last Post: 08-06-2008, 12:58 PM
  3. Login page
    By banie in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 07-03-2008, 03:05 PM
  4. problems with my JSP login page
    By ilangocal in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 04-28-2008, 07:40 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
  •