• Post Reply Bookmark Topic Watch Topic
  • New Topic

at hashcode() which object associated with it  RSS feed

 
ravi suthar
Greenhorn
Posts: 17
Firefox Browser Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

suppose in my login code,
if i will store hashcode() of password instead of password string,
next time for verification of password how i get password String from hashcode(),
is there any method in java which returns what object associated with a particular hashcode()



output: -1066781514 (some hashcode value)




 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ravi suthar wrote: is there any method in java which returns what object associated with a particular hashcode()

No, simply because no object is associated with a particular hashCode (not hashcode -- Java is case sensitive).
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ravi suthar wrote:i will store hashcode() of password instead of password string

Did you want to say 'hash' here? It is a common practice to store hash of a password in DB and there are different hashing techniques/algorithms available. Purpose/contract of hashCode method is different one.

I hope this helps.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ravi suthar wrote:
if i will store hashcode() of password instead of password string,
next time for verification of password how i get password String from hashcode(),

First of all, as Anayonkar already said, you should not store the Java hashCode() of the password string - instead, use a cryptographically strong hashing algorithm such as SHA-256. The Java hashCode() and hashing algorithms are not the same kind of thing, although they both use the word "hash". Don't confuse them!

For the second part, you cannot get the password back if you just have the hashCode(), or if you have a hash from an algorithm such as SHA-256. Hashing algorithms are designed to work one way only: you can compute the hash over some data, but it is not possible to get the original data back if you only have the hash.

For password verification, you do not need to get the original password back from the hash. How it usually works is this: user enters a password to login, you compute the hash over what the user entered, and then you compare that hash with the hash that you have in the database. If they are equal, then what the user entered was the correct password.
 
ravi suthar
Greenhorn
Posts: 17
Firefox Browser Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you Jesper de Jong, Anayonkar Shivalkar, Darryl Burke.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!