aspose file tools*
The moose likes JDBC and the fly likes Verifying Username & Password Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Verifying Username & Password" Watch "Verifying Username & Password" New topic
Author

Verifying Username & Password

Ranjeet Deshmukh
Ranch Hand

Joined: Jan 18, 2013
Posts: 31

Hi All,

I'm doing JDBC with Mysql 5.2, I'm storing my password using md5 encryption. Program should show error message when password entered from command line is not matched with password stored in DB. Tell me what will to replace "?" in if().

My code is:-



~R@njeet.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38389
    
  23
Why are you using a password without a user name? Why are you showing the password in clear on the command terminal? Why have you got the root password unencrypted in that code? Why have you got pairs of variables which differ only in the case of their first letter?
Ranjeet Deshmukh
Ranch Hand

Joined: Jan 18, 2013
Posts: 31

Campbell Ritchie wrote:Why are you using a password without a user name? Why are you showing the password in clear on the command terminal? Why have you got the root password unencrypted in that code? Why have you got pairs of variables which differ only in the case of their first letter?



This is just a basic program, I'm accepting password and if it is correct then I'm greeting the user with username associated with password and if password is wrong then displaying an error message. "Password" is accepting the password from user at CL and "password" contains the root password for Mysql.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38389
    
  23
You would have to check the password against those retrieved. If it is an MD5, what form does it return the result in? Is it a BigInteger? Use its equals() method. What you are doing is working out an existential quantification
x • MD5(x) ∈ passwordMD5s
What you ought to do is use a password field or the Console class’ method for password, and ask for user name and password before you set up the connection at all. Don’t use the root password.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Verifying Username & Password