• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Verifying Username & Password

 
Ranjeet Deshmukh
Ranch Hand
Posts: 35
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:-

 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic