Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have used GetHashCode() to encrypt password field.
When new user is created the password entered by user is stored in hascode value like

C#
string pswd = txtPassword.text.GetHashCode();


then this pswd string is stored in database. After that when user login to his account then again I convert user's entered value in hascode value like

C#
string userPassword = txtEnterPassword.text.GetHashcode();


Then I check the value of the password saved in database and user's text is matching or not. This working fine in my development server.

But when I uploaded this page in live server it's not working. When user create new account and after that he try to login with his correct password he cannot login to the page.

I searched the solution in msdn then I read this line: 'The default implementation of the GetHashCode method does not guarantee unique return values for different objects.' What I should to do now. Please anyone have any idea?
Posted
Updated 10-Oct-12 10:26am
v2

Your best bet is not to do it that way. See these code project resources for how you can approach your password encryption issues:

Password Storage: How to do it.[^]
Fractal encryption algorithm[^]
The Art & Science of Storing Passwords[^]
 
Share this answer
 
Comments
Abhinav S 10-Oct-12 23:38pm    
Good links.
Well, either you can override and provide your own GetHashCode() or you can use MD5 to generate a hash based on the value input.

This link talks about GetHashCode(): Link GHC[^]

and this link talks about MD5: Link MD5[^]

PS: I have used MD5 in the past with reasonable success to generate a hash based on the user input value and then store this hash as an "encrypted" password.
 
Share this answer
 
v2
I searched the solution in msdn then I read this line: 'The default implementation of the GetHashCode method does not guarantee unique return values for different objects.'
That is not going to be the issue here. I believe this just means that 2 different objects can have the same hash value (not unique), not vice versa, which is your concern.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900