CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: login page

  1. #1
    Join Date
    Dec 2002
    Location
    malaysia
    Posts
    7

    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");

    }

  2. #2
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163
    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.

  3. #3
    Join Date
    Dec 2002
    Location
    malaysia
    Posts
    7
    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!

  4. #4
    dlorde is offline Elite Member Power Poster
    Join Date
    Aug 1999
    Location
    UK
    Posts
    10,163
    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
  •  





Click Here to Expand Forum to Full Width

Featured