• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help with my Username and password system  RSS feed

 
Chris McBurn
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys so im making a username and password system to transfer to a different form. The username and password is from a Access database and validated to see if the right credentials are entered.




So when I enter the username and passwords, they work! but where would I put a JOptionPane message saying wrong Username or Password? Every time I do this it pop ups and loops constantly and then I get the error...

net.ucanaccess.jdbc.UcanaccessSQLException: invalid cursor state: identifier cursor not positioned on row in UPDATE, DELETE, SET, or GET statement: ; ResultSet is positioned after last row


Can you please help me to get this to work thanks..
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

I have change the quote tags to code tags which are appropriate for code, and doesn't it look better.

You have all sorts of security hazards there.
Don't use a String to transfer a password. Use a char[] instead, and empty the array by using something like Arrays#fill after you have used it. Don't use a text field for a password; use a password field. Don't store passwords in a database. Use the database's password function to hash the password; you should be able to get more details from the program's handbook.

Never write == false or == true, which are both dangerously error‑prone. If you write = by mistake you can get two errors for the price of one.
Never if (b == true) ... Always if (b) ...
Never if (b == false) ... Always if (!b) ...

Why are you catching plain simple Exception? What sort of exception do you expect? Catch that instead. You should probably not be catching Exceptions in a listener in the first place. There should be other code (preferably in another class) which does the database reading and that should probably handle any exceptions. It is possible that you have an SQLException. Remember that unlike most kinds of exception, an SQLException has methods to get the error code and other details from the databases. That is information not available to other sorts of exception.
 
Liutauras Vilda
Sheriff
Posts: 4917
334
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Never write == false or == true, which are both dangerously error‑prone. If you write = by mistake you can get two errors for the price of one.

And here is the one of scenario's demonstration mentioned in quote above:
Output: Give away for free
 
Chris McBurn
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Ive made a few changes and watched a few tutorials and I came up with this piece. it works perfectly, Im only a beginner so using char[] seems abit difficult just yet!
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should use try with resources for your result set and prepared statements, so you don't have to close either explicitly. If you don't use a finally or try with resources, an exception elsewhere may mean the statement or result set are never closed.
I think you are checking in the wrong place. You should make the table reject duplicates; there is probably a simple way to do that with DISTINCT in the SQL. You will probably suffer an SQLException if you try to insert duplicates, but most SQL classes/interfaces declare that Exception in their code already, so the compiler will force you to handle it regardless, and your code won't look any different.
You ought not to open and close connections in your GUI class. There should be a class somewhere else representing an interface which does the logging on and verifies the password.
What type is UserPage? You will get a very peculiar GUI if you have windows and dialogues appearing and disappearing all the time. You will get much better results if you make up (not at all a good name for a page) visible all the time, and simply let its text appear or disappear. It depends what layout you are using. I am not familiar with card layout, but many people say it is good for things like this. I think it is like a stack of cards and you bring a particular card to the top. Tabbed panes are rather similar.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!