Integrating MediaWiki's users to a personal ASP.NET Website
Fragment of a discussion from Project:Support desk
Here's your solution:
public Byte[] createWikiUserPassword(string newPassword)
{
// Wikipassword in format ":B:" + salt + ":" + md5 hash of ( salt + "-" + md5 hash of (password) )
// Create Salt
Byte[] salt = new Byte[4];
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
rng.GetBytes(salt);
MD5 md5 = MD5.Create();
string strSalt = hash2hexstring(salt);
// MD5 has of password
Byte[] hashPassword = md5.ComputeHash(Encoding.UTF8.GetBytes(input));
string strHashPassword = hash2hexstring(hashPassword);
// MD5 hash of salt + dash + hashPassword
Byte[] md5saltPasswordHash = md5.ComputeHash(enc.GetBytes( strSalt + "-" + strHashPassword ));
string strMd5SaltPasswordHash = hash2hexstring(md5saltPasswordHash);
string strUserPassword = ":B:" + strSalt + ":" + strMd5SaltPasswordHash;
// Total result
Byte[] userPassword = enc.GetBytes(strUserPassword);
return userPassword;
}
private string hash2hexstring(byte[] input)
{
string strInput = BitConverter.ToString(input);
strInput = strInput.Replace("-", "");
strInput = strInput.ToLower();
return strInput;
}