0

I'm trying to create new passwords to Joomla 2.5 using C#.

I've tried the method where I hash some pass with MD5CryptoService and then concat a salt string with 32 characters, but without success.

var provider = new MD5CryptoServiceProvider();

var bytesFromPassword = System.Text.Encoding.ASCII.GetBytes("my_password");
var hash = provider.ComputeHash(bytesFromPassword);

Random random = new Random((int) DateTime.Now.Ticks);
byte[] salt = new byte[32];
random.NextBytes(salt);

string hashTo64 = Convert.ToBase64String(hash);
string saltTo64 = Convert.ToBase64String(salt);

var formattedPassword = string.Format("{0}:{1}", hashTo64, saltTo64);

Is something wrong with this code?

Do I need to change something?

Does Joomla 2.5 uses a new cryptography method that is different than this way I'm trying to do?

Thank you all!

Kiwanax
  • 1,265
  • 1
  • 22
  • 41

2 Answers2

0

I solved the question using these two questions below:

using php to create a joomla user password?

How convert byte array to string

Hope it can help someone as well!

Community
  • 1
  • 1
Kiwanax
  • 1,265
  • 1
  • 22
  • 41
0

At the moment the salt you are creating is not used to salt the password. From my understanding of Joomla the password is saved as a hexadecimal string.

First you would have to include the salt in the bytesFromPassword

var salt = "ThereAreManySaltsButThisOneIsMine";
var bytesFromPassword = Encoding.ASCII.GetBytes("my_password" + salt);
var hash = provider.ComputeHash(bytesFromPassword);

var hashString = GenerateHexadecimalStringFromBytes(hash);
var formattedPassword = string.Format("{0}:{1}", hashString, salt);

Helper method to convert the byte array into hexadecimal string:

private static string GenerateHexadecimalStringFromBytes(byte[] hash)
{
        StringBuilder sBuilder = new StringBuilder();

        // Loop through each byte of the hashed data  
        // and format each one as a hexadecimal string. 
        foreach (byte t in hash)
        {
            sBuilder.Append(t.ToString("x2"));
        }
        return sBuilder.ToString();
    }
Mads
  • 444
  • 1
  • 5
  • 15