I am trying to get back a string from its hash value?
string str="Hello";
int hashStr=str.GetHashCode(); // hash value of "Hello" is -694847
can I get back my_string (i.e "Hello") form the hashed value....?
UPDATED
actually i am thinking to save password into my database after hashing to make it secure...
So it means a different password even have same value?
There are exactly 2^32 many hash codes but way, way more strings. Thus, by the pigeonhole principle, there have to be multiple strings mapping to the same hash code. Therefore, an inverse map from hash code to string is impossible
Edit: Response to your update.
actually i am thinking to save password into my database after hashing to make it secure...
So it means a different password even have same value?
Yes, it is possible for two passwords to have the same hash. This is basically a restatement of the above. But you shouldn't use GetHashCode to hash the password. Instead, use something secure like SHA-2.
To go one step further, never try to roll your own your encryption/security etc. Find a library that does it for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With