File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes JDBC validating username and password against SQL database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "JDBC validating username and password against SQL database" Watch "JDBC validating username and password against SQL database" New topic
Author

JDBC validating username and password against SQL database

Dene Lamprecht
Greenhorn

Joined: Jun 23, 2009
Posts: 14

Hi People
I've got a problem: I need to create a database(SQL) to store username and passwords. I've made the database. Now I need to write a Login Screen(Java application) where users can input the username and password, the Java Application needs so verify that the username and password matches the respective entry in the database, if any.

This is what I've done:




The errors I'm getting says that my "Username did not match the database" and I'm sure that it should because it is the correct username


the usernames and passwords entered in my database are as follows:



Please tell me what I'm doing wrong
Thanks
Dene
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
Try with



== for object types compares reference not the value.
Dene Lamprecht
Greenhorn

Joined: Jun 23, 2009
Posts: 14
Purushothaman Thambu wrote:Try with



== for object types compares reference not the value.


Thank you Purushothaman is works great now, thank you for taking the time to help
Dene
Agador Paloi
Ranch Hand

Joined: Jan 24, 2006
Posts: 118
If you are building a secure database you should not be keeping the actual password in your database.
The password should be kept as an encrypted value and when the
user enters their password it is encrypted with the same algorithm
and compared to the database value.

Agad
Dene Lamprecht
Greenhorn

Joined: Jun 23, 2009
Posts: 14
Agador Paloi wrote: If you are building a secure database you should not be keeping the actual password in your database.
The password should be kept as an encrypted value and when the
user enters their password it is encrypted with the same algorithm
and compared to the database value.

Agad


Hi Agad
It's sounds like the better thing to do, the problem is that i don't know how to do it. Is it something that I am supposed to do inside my SQL database or in my Java code?

In my Java code I have tried to change the password field to a JPasswordField but I get an error on this piece of code:


The message is:

Can you please tell me what I'm doing wrong and what I should do, or maybe a tutorial on how to fix it?

Thank you in advance
Dene
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30130
    
150

Dene,
If you look at the String class JavaDoc, there should be something about converting a char[] to a String. I think it's one of the constructors.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Agador Paloi
Ranch Hand

Joined: Jan 24, 2006
Posts: 118
JPassword does not do any encryption, it just doesnt display the entered field
on the screen. You could use something like MessageDigest to create
an encrypted password :

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDBC validating username and password against SQL database
 
Similar Threads
Making co-ordinates co-operate!
Can someone please help
Retrieving components inserted into a JTextPane
I would like to ask a question about java
Runtime Changes to Your GUI