Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-01-2008, 04:09 PM
Member
 
Join Date: Jan 2008
Posts: 21
Rep Power: 0
banie is on a distinguished road
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:
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>
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 09-09-2008, 09:37 AM
Member
 
Join Date: Sep 2008
Posts: 17
Rep Power: 0
sagarbirari is on a distinguished road
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
__________________
Sagar Birari
Development & Technical Blog
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to return to login page once logout peiceonly Suggestions & Feedback 2 03-31-2009 08:50 PM
JSP - Login Page Example JavaForums Java Blogs 5 01-13-2009 04:02 PM
login page keerthi_y19 New To Java 9 08-06-2008 12:58 PM
Login page banie JavaServer Pages (JSP) and JSTL 2 07-03-2008 03:05 PM
problems with my JSP login page ilangocal JavaServer Pages (JSP) and JSTL 1 04-28-2008 07:40 PM


All times are GMT +2. The time now is 08:17 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org