Question

I'm currently working on a C# application that sends a request to a php webserver which then validates a MySQL connection. The hashing algorithm is on the server, which works fine, but I want the same hashing technique in my C# application. The md5 hashing is from ipBoard forums, which is why it needs to be this one specifically. Here's how it states according to them:

"The hash is the md5 sum of the md5 sum of the salt concatenated to the md5 sum of the plaintext password. Expressed in PHP code, this is as follows: $hash = md5( md5( $salt ) . md5( $password ) ); "

I just don't know where to start with this in c#.. Thanks for any responses.

Was it helpful?

Solution

If you just need a quick, ported version of the supplied PHP code:

// Create the MD5 hash object.
System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create ();

string password = "password";
string salt = "salt";

// Hash password and salt
byte[] passwordHash = md5.ComputeHash (System.Text.Encoding.ASCII.GetBytes (password));
byte[] saltHash = md5.ComputeHash (System.Text.Encoding.ASCII.GetBytes (salt));

// Combine password and hash.
string passwordAndSalt = System.Text.Encoding.ASCII.GetString (passwordHash) + System.Text.Encoding.ASCII.GetString (saltHash);

// Compute final hash against the password and salt.
byte[] finalHash = md5.ComputeHash (System.Text.Encoding.ASCII.GetBytes (passwordAndSalt));

See the System.Security.Cryptography.MD5 docs for more info.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top