Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I generate an encryption hash in ASP.NET MVC?

I am looking into creating a custom members login system (for learning) and I haven't been able to figure out the C# command to generate an encrypted hash.

Is there a certain namespace I need to import or anything like that?

like image 834
quakkels Avatar asked May 10 '10 17:05

quakkels


1 Answers

Using the namespace System.Security.Cryptography:

MD5 md5 = new MD5CryptoServiceProvider();
Byte[] originalBytes = ASCIIEncoding.Default.GetBytes(originalPassword);
Byte[]  encodedBytes = md5.ComputeHash(originalBytes);

return BitConverter.ToString(encodedBytes);

or FormsAuthentication.HashPasswordForStoringInConfigFile method

like image 177
Gregoire Avatar answered Nov 15 '22 01:11

Gregoire