views:

171

answers:

4

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?

Thanks for any help.

A: 

Well, first of all an encryption hash is a contradiction. Like a vegetarian steak. You can use encryption, or you can hash them (and you should hash them), but hashing is not encryption.

Look up a class starting with Md5 ;) Or Sha1 - those are hash algoryithms. It is all there in .NET (System.Security.Cryptography namespace).

TomTom
Thanks for that clarification!
quakkels
A: 

One way hashes are simpler to run and MUCH safer.

http://www.dreamincode.net/code/snippet1959.htm

ondesertverge
A: 

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

Gregoire
So I need to convert originalPassword from a string to type of Byte[]?
quakkels
@quakkels: Yes as done in line 2 because the function take an array of byte
Gregoire
Sweet... I just needed to use using System.Text and this worked great!! ty
quakkels