• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

at hashcode() which object associated with it

 
Greenhorn
Posts: 17
Firefox Browser Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)




 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you Jesper de Jong, Anayonkar Shivalkar, Darryl Burke.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic