|
-
December 20th, 2002, 02:29 PM
#1
login page
I can use this login page to log in to another page(MainFrame) successfully but got some problems. When i try to enter the username (which is not match the uppercase and lowercase with the data in database), i still can successfully log in. Why? Actually the username should be case sensitive. Can somebody help me? thanks.
==============================================
void jButton1_actionPerformed(ActionEvent e) {
String userid = jTextField1.getText(); //username
char[] passwd = jPasswordField1.getPassword(); //password
System.out.println( "User ID is : " + userid);
try
{
connection = getDBConnection();
String query = "SELECT * FROM UserInfo WHERE UserID= '"+ userid +"' AND Password= '"+ passwd +"'";
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery( query );
//displayResultSet ( resultSet );
resultSet.next();
String dbUserID = resultSet.getString("UserID");
if (dbUserID != null)
{
String dbUserPasswd = resultSet.getString("Password");
System.out.println("dbUserID: " + dbUserID);
System.out.println("dbUserPasswd: " + dbUserPasswd);
this.hide();
new MainFrameClass(); //to new page
}
else
{
System.out.println("dbUserID is null");
}
statement.close();
connection.close();
}
catch(SQLException sqlex)
{
System.out.println("DB Connection failed: " + sqlex);
//throw new SQLException("DB Connection failed");
}
-
December 20th, 2002, 06:54 PM
#2
This looks like a SQL question. If it's MS SQL Server, try Case-sensitive comparisons and SQL Server Magazine. Otherwise try SQL Guru.
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
December 20th, 2002, 10:28 PM
#3
thanks for the reply. actually the database i'm using is Microsoft Access not SQL server, therefore i don't really understand what should i do with my sql statement above. please help!
-
December 21st, 2002, 07:03 AM
#4
Ideally, your SQL query needs to do a case-sensitive comparison. MS Access comparisons are case-insensitive by default. I don't know MS Access, so you'll have to check your Access documentation to see if you can change this.
Alternatively, you could compare the password field(s) in the record(s) returned in the ResultSet with the original password using String.compareTo(...). This is case sensitive. If the result of a compare is zero, the strings are a lexicographic match, which is what you want.
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|