Bsbosa.com
07-14-2010, 09:54 PM
I'm working on loging into an SMF based message board using a WebClient with a cookie collection. So far I've been able to use existing cookies to connect and download pages as needed, however I have to hard code the cookies to do it. Obviously not a good option.
The problem I'm running in to is that in order to have the server generate credentials I have to give it a log in name and a hashed password. The forum login generates them using sha1 hashing with this code:
doForm.hash_passwrd.value = hex_sha1(hex_sha1(doForm.user.value.php_to8bit().p hp_strtolower() + doForm.passwrd.value.php_to8bit()) + cur_session_id);
I've been trying to use
private void btnLogin_Click(object sender, EventArgs e)
{
String sName = "test";
String sPassword = "login";
String sSessionID = "3d847dffa233343cc5065a82b73d566e";
SHA1 sha = new SHA1CryptoServiceProvider();
byte[] sResult = sha.ComputeHash(StrToByteArray(sName + sPassword));
sResult = sha.ComputeHash(StrToByteArray(ByteArrayToStr(sRes ult) + sSessionID));
}
public static byte[] StrToByteArray(string str)
{
return Encoding.UTF8.GetBytes(str); //encoding.GetBytes(str);
}
public static string ByteArrayToStr(byte[] bytes)
{
return BitConverter.ToString(bytes).Replace("-", "").ToLower();
}
To generate the same hash as the php version...however it's obviously failing. Somewhere in there I'm missing some encoding or particular formatting that I don't know about. Can anyone point me in the right direction here?
The problem I'm running in to is that in order to have the server generate credentials I have to give it a log in name and a hashed password. The forum login generates them using sha1 hashing with this code:
doForm.hash_passwrd.value = hex_sha1(hex_sha1(doForm.user.value.php_to8bit().p hp_strtolower() + doForm.passwrd.value.php_to8bit()) + cur_session_id);
I've been trying to use
private void btnLogin_Click(object sender, EventArgs e)
{
String sName = "test";
String sPassword = "login";
String sSessionID = "3d847dffa233343cc5065a82b73d566e";
SHA1 sha = new SHA1CryptoServiceProvider();
byte[] sResult = sha.ComputeHash(StrToByteArray(sName + sPassword));
sResult = sha.ComputeHash(StrToByteArray(ByteArrayToStr(sRes ult) + sSessionID));
}
public static byte[] StrToByteArray(string str)
{
return Encoding.UTF8.GetBytes(str); //encoding.GetBytes(str);
}
public static string ByteArrayToStr(byte[] bytes)
{
return BitConverter.ToString(bytes).Replace("-", "").ToLower();
}
To generate the same hash as the php version...however it's obviously failing. Somewhere in there I'm missing some encoding or particular formatting that I don't know about. Can anyone point me in the right direction here?