Problem with Encrypted data  
Author Message
K. Ravinder Reddy





PostPosted: Visual C# General, Problem with Encrypted data Top

Hi,
I am working on the Login screen. In my database I have USERNAME and PASSWORD in Encrypted format. From my Login screen I am reading the values (login name, password which are in plain text format) and I have to compare these values with the database values(which are in Encrypted format) How can I do this. Please help me out.



Visual C#7  
 
 
GavH





PostPosted: Visual C# General, Problem with Encrypted data Top

If you used a good encrption algorthym the process should be one way, so the basic principle is to encrypt the plain text username and password using the same mechanism and compare them to the encrypted set in the database, for example (un tested) :

using System.Web.Security; //you must add reference also

//convert the text username and pass to encrpyted version in this case an MD5 hash
string sHashUser = FormsAuthentication.HashPasswordForStoringInConfigFile(sUserName, "md5");
string sHashPass = FormsAuthentication.HashPasswordForStoringInConfigFile(sPass, "md5");

//now you have a hashed username and password locally, and a hashed username and password //in the database.

/*Do something to check hashed user and pass against those in database, hopefully a stored procedue!

Or if you have the databse versions of the hashed username and password locally simply compare the strings :
*/

if(sDBUser == sHashUser && sDBPass = sHashPass)
{
//user is authenticated.
}
else // Self destruct.

Regards







 
 
Zeeshan Ahmed





PostPosted: Visual C# General, Problem with Encrypted data Top

Please visit the following link. I hope this will help you.

http://www.codeproject.com/dotnet/encryption_decryption.asp

Regards