Integrating MediaWiki's users to a personal ASP.NET Website

Fragment of a discussion from Project:Support desk
Jump to: navigation, search

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;
       }
80.254.146.13214:35, 27 April 2012

Sorry, I missed the declaration if 'enc':

private System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();

Cheers,

Carl.

80.254.146.13214:36, 27 April 2012

You can edit your post you know.

Krenair (talkcontribs)14:59, 27 April 2012