Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Any one know that how to encrypt the password for login Table and how to dycrypt it..
At the the Login Time. ???

[edit]Subject only: DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously. - OriginalGriff[/edit]
Posted
Updated 25-Apr-11 1:37am
v3

Don't.

Hash it instead. Look at the System.Cryptography namespace, and use SHA hashing to generate a value to store in you database. When you need to check it, hash whatever the user gave you, and compare the hashes. If they are the same, the user can be logged in. If not, he can't.

It is also a good idea to include the username or Id in the data before you hash it, so that two users with the same password do not generate the same hash value.

If you use encryption, you need a key in your code which decrypts it - this posses a big security risk. Hashing does not need a key because it is one-way.

[edit]

I have written up a description of this with appropriate code as a Tip / Trick: Password Storage: How to do it.[^]
It should be available soon, depending on how quickly article moderation is going today!

OriginalGriff
[/edit]
 
Share this answer
 
v2
Comments
thatraja 25-Apr-11 7:42am    
Fine answer OG
Sergey Alexandrovich Kryukov 25-Apr-11 11:35am    
Good answer, my 5.
--SA
To securely store a password so that it can be read back, use the
ProtectedData
class.


public static string ProtectPassword(string password)
{
    byte[] bytes = Encoding.Unicode.GetBytes(password);
    byte[] protectedPassword = ProtectedData.Protect(bytes, null, DataProtectionScope.CurrentUser);
    return Convert.ToBase64String(protectedPassword);
}

public static string UnprotectPassword(string protectedPassword)
{
    byte[] bytes = Convert.FromBase64String(protectedPassword);
    byte[] password = ProtectedData.Unprotect(bytes, null, DataProtectionScope.CurrentUser);
    return Encoding.Unicode.GetString(password);
}
 
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