Search code examples
javasecuritypasswordspassword-protectionpassword-encryption

how can I get the String from hashCode


I am working on a project where I had got my password field value's hashCode and stored that hashCode in DB for security purposes.Now I want to recover the password from the hashCode.How can I do it? Is it possible to get the String value back from the hashCode?If it is not, can anyone suggest me a better way to store my password in anyother format?


Solution

  • You know that several objects can have same hash(), as it mentioned in java doc for Object.hashCode()

    It is not required that if two objects are unequal * according to the {@link java.lang.Object#equals(java.lang.Object)} * method, then calling the {@code hashCode} method on each of the * two objects must produce distinct integer results.

    It's obvious you can't restore different objects from same hash code, so it's impossible at all, simple logic.