I have two problems

1) I want to display the customer details like account number, name, dob, etc. in a different customer account frame (written in another class) and hence I want that the same username that I logged in with, to use in the select query( i.e. select * from [tablename] where [the sameusername I logged in with] ) in the customer account page. How can I do that?

2) When checking for validity of username and password it works fine when I type in a username that exists in the database. But for any other username it does not display and error.

{
            
            un1 = tusername.getText();
            String p1 = new String(tpassword.getPassword());
            query="select * from customer.details;";
            ResultSet rs = smt.executeQuery(query);
                             
           if(un1.equals("") && p1.equals(""))
            {
                JOptionPane.showMessageDialog(null, "Enter your username and password","Error", JOptionPane.ERROR_MESSAGE);
            }
        else if (un1.equals(""))
            {
               JOptionPane.showMessageDialog(null, "Please enter your username","Error", JOptionPane.ERROR_MESSAGE);
            }

        else if (p1.equals(""))
            {
                JOptionPane.showMessageDialog(null, "Please enter your password","Error", JOptionPane.ERROR_MESSAGE);
             }

        else
          
           while(rs.next())
           {                               
                        if(un1.equals(rs.getString("cust_username")))
                        {
                            if(p1.equals(rs.getString("cust_password")))
                            {
                                 CustomerBankingPage cbp = new CustomerBankingPage();
                                 cbp.custbanklaunch();
                                 loginframe.setVisible(false);
                                
                            }
                        else                                                           
                            {
                               JOptionPane.showMessageDialog(null, "Username/Password do not match","Error", JOptionPane.ERROR_MESSAGE);
                            }
                           
                       }

Recommended Answers

All 2 Replies

Because, according to your logic, you are only displaying an error when the username matches but the password does not. Why do you not simply query with the username and password and let the DB do the work? Also, you should not be storing plaintext passwords anywhere. Use MD5 and hash them and store that hash, then hash what the user enters and compare those hashes.

The password and username thing worked. Thanks.

How do we use MD5 and hash feature for password?

Also if you kindly let me know how to tackle my problem in 1) above

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.