File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes User Name and Password Verification Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "User Name and Password Verification" Watch "User Name and Password Verification" New topic

User Name and Password Verification

omar salem
Ranch Hand

Joined: Aug 22, 2006
Posts: 34
Hi Ranchers,

I am trying to validate a user name and a password by comparing details in the database with those provided by the user inside the text fields of the simple frame created for this test. the condition gets always true even if the entries do not match details from the database and always gives me the message "Match Found". Here is the code i worte for this :

I would appreciate your help and fast response.
Omar Salem

Have a sip of Java !!!
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63858

Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.

[Asking smart questions] [About Bear] [Books by Bear]
omar salem
Ranch Hand

Joined: Aug 22, 2006
Posts: 34
Thanks Bear....Never known about code tags before
Jan Cumps

Joined: Dec 20, 2006
Posts: 2565

Try to print out all the values, and compare for yourself.

Some comments: do not use

You could simplify your code by using a where clause:
Bind your username and password using a PreparedStatement in stead of a Statement, and execute it.

If your query returns anything (next() == true), then you have a match.
No need to retrieve all possible records, and looping over them.

You could increase security of your code by searching for a good security mechanism. Your mechanism sends readable user name and password over the network.

OCUP UML fundamental and ITIL foundation
omar salem
Ranch Hand

Joined: Aug 22, 2006
Posts: 34
Thanks for your help.......I really got it to work now...Thanks again
Omar Salem
I agree. Here's the link:
subject: User Name and Password Verification
It's not a secret anymore!