| Author |
Login code
|
Aravind Prasad
Ranch Hand
Joined: Dec 28, 2005
Posts: 258
|
|
Hello Ranchers!! I'm doing a form design in java swing!! now i developed the login dialog.. with username.. password.. and 2 buttons!! After entering the username and password when i click the login button it has to verify thru the code.. and if both are correct show.. Login success dialog!! it is showing when i given some and checked it mandatory!! when i connected it to database!! it is not showing error!! each and everytime it is showing the incorrect password message box.. and finally when both the usename and pwd are correct shows the login success message box!! now.. this is my code!! for process login() ------------------------------------------------------------------- public void processLogin() { try { try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(ClassNotFoundException e) { //out.println(e); //JOptionPane.showMessageDialog(null, e); System.exit(0); } String dbURL = "jdbc dbc:login"; Connection dbCon = DriverManager.getConnection(dbURL); String query = "Select * from login"; Statement stmt = dbCon.createStatement(); ResultSet rs = stmt.executeQuery(query); while(rs.next()) { String data_name = rs.getString(1); String data_pass = rs.getString(2); //verfication part if(name.equals(data_name)) { if(pass.equals(data_pass)) { JOptionPane.showMessageDialog(null, "Login Success"); break; } else { JOptionPane.showMessageDialog(null, "Invalid Password"); } } else { JOptionPane.showMessageDialog(null, "Authentication Failed !!"); } } } catch(SQLException e) { System.exit(0); } } --------------------------------------------------------------------- i think this code is correct but when ever it passes thru the if conditions.. and if the username is incorrect it will be showing the messagebox "authentication failed " ------------------------------------------------------------------------ please help me ranchers!! thanks in advance!!
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16680
|
|
i think this code is correct but when ever it passes thru the if conditions.. and if the username is incorrect it will be showing the messagebox "authentication failed "
Quick glance at your code... Isn't that what it is supposed to be doing? Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Shyam Prasad Murarka
Ranch Hand
Joined: May 02, 2005
Posts: 209
|
|
Dear Aravind, I am going to format your code properly and you will see the answer to your question. Now you will be able to see that the corresponding "else" block for the "if" block where the userName is checked prints out the "Authentication failed" message. So was it this that you wanted to know??
|
With Best Regards,
Shyam Prasad Murarka
|
 |
Aravind Prasad
Ranch Hand
Joined: Dec 28, 2005
Posts: 258
|
|
Hello Shyam Prasad Murarka, thannks for the idea!! but if i type the wrong user name it should be able to show the message box authentication failed!! so.. for that.. what i want to do?
|
 |
Jan Groth
Ranch Hand
Joined: Feb 03, 2004
Posts: 456
|
|
pure curiosity: how did you put the double "!!" on you keyboard? did you have to remove any other keys for it? jan
|
 |
Shyam Prasad Murarka
Ranch Hand
Joined: May 02, 2005
Posts: 209
|
|
Dear Aravind, I am confused now! What are you trying to tell? Is the "Authentication Failed!!" message showing up or not when you type the wrong user name? Do you want it to show up? And where did you get the habit of typing "!!"? Is it from the the constant number of sms-es that you keep sending?
|
 |
 |
|
|
subject: Login code
|
|
|