Mark Harris wrote:MD5 is a one way encryption, Zen cart also salts it before MD5 so there is now way to check it. I'd have to modify the login code in AC to be the same as Zen Cart, however i cant do that because i dont have the source code to your Commerce Builder project

If you can determine the salt value, and your cart adds the salt value to the end of the plain text, you can convert them without a source modification. I don't know how Zen cart uses and saves the salt, but you might.
AC7 passwords are not stored quite the same way. We take the bytes of the hash, append the salt bytes, then encode the whole mess in base 64. The base 64 encoded value is what goes to the database.
Here is some code that you can use to convert MD5 or SHA1 hashes over to a format understood by AbleCommerce 7.
Code: Select all
private Byte[] HexToBytes(string hexhash)
{
if (string.IsNullOrEmpty(hexhash)) return null;
if (hexhash.Length % 2 == 1) hexhash = "0" + hexhash;
int arr_size = hexhash.Length / 2;
Byte[] bytes = new Byte[arr_size];
for (int i = 0; i < arr_size; i++)
bytes[i] = Convert.ToByte(hexhash.Substring(i * 2, 2), 16);
return bytes;
}
private string ConvertFromHexHash(string hexhash, byte[] saltBytes)
{
//FIRST, TURN THE HEX DIGEST INTO AN ARRAY OF BYTES
byte[] hashBytes = HexToBytes(hexhash);
if ((hashBytes == null) || (hashBytes.Length == 0)) return string.Empty;
//MAKE SURE THE SALT BYTES ARRAY IS NOT NULL
if (saltBytes == null) saltBytes = new byte[0];
//CREATE NEW ARRAY THAT WILL COMBINE HASH VALUE WITH SALT BYTES
byte[] hashWithSaltBytes = new byte[hashBytes.Length + saltBytes.Length];
//COPY HASH BYTES INTO ARRAY
for (int i = 0; i < hashBytes.Length; i++)
hashWithSaltBytes[i] = hashBytes[i];
//APPEND SALT BYTES INTO ARRAY
for (int i = 0; i < saltBytes.Length; i++)
hashWithSaltBytes[hashBytes.Length + i] = saltBytes[i];
//ENCODE THE COMBINED BYTE ARRAY TO BASE 64 STRING
string hashValue = Convert.ToBase64String(hashWithSaltBytes);
//UPDATED HASH VALUE IS READY FOR STORAGE
return hashValue;
}
Let me break this down in an example of where it can be used. If you hash
password using MD5 without any salt value, the digest will look like this: 5f4dcc3b5aa765d61d8327deb882cf99
Then to put into AbleCommerce, we have to convert that digest into the 16 bytes it represents. There is no salt to append, and we encode those bytes into base 64 to get the final result: X03MO1qnZdYdgyfeuILPmQ==
Suppose we hash
password and append the salt value
a. Our digest will look like this: f2f555205f367f5b51faee7ebb8dcc1b.
Again we convert that to the 16 byte array. We apend one byte for the "a" salt value, ending up with a 17 byte array. The 17 bytes are base 64 encoded to get the final result: 8vVVIF82f1tR+u5+u43MG2E=
So again, if you can determine the salt used by zen cart, and the plain text that is hashed is
password + salt then you can directly convert them. Otherwise, you should be able to use the code above to generate your own passwords as you see fit. Just create an MD5 or SHA1 hash of the desired password + salt, then pass the values into the convert method. It will produce a value you can store into the ac_UserPasswords table.