Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. SMF Forum login using webclient [modified]

SMF Forum login using webclient [modified]

Scheduled Pinned Locked Moved C#
phpsysadmincryptographyhelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Skymir
    wrote on last edited by
    #1

    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().php_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(sResult) + 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? EDIT: String sName = "test"; String sPassword = "login"; String sSessionID = "8000e537c2a7a31547ffa779fab7a1e2"; String sTemp; SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider(); sTemp = BitConverter.ToString(sha.ComputeHash(Encoding.UTF8.GetBytes(sName + sPassword))).Replace("-", "").ToLower(); textBox2.Text = BitConverter.ToString(sha.ComputeHash(Encoding.UTF8.GetBytes(sTemp + sSessionID))).Replace("-", "").ToLower(); After beating my head against a wall long enough I was able to come up with this, and it does spit out the exact same hash as the existing php code. This should allow anyone to generate a hash for logging into most SMF powered message boards (They seem to have a niche market in games and mods on a global scale

    E 1 Reply Last reply
    0
    • S Skymir

      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().php_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(sResult) + 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? EDIT: String sName = "test"; String sPassword = "login"; String sSessionID = "8000e537c2a7a31547ffa779fab7a1e2"; String sTemp; SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider(); sTemp = BitConverter.ToString(sha.ComputeHash(Encoding.UTF8.GetBytes(sName + sPassword))).Replace("-", "").ToLower(); textBox2.Text = BitConverter.ToString(sha.ComputeHash(Encoding.UTF8.GetBytes(sTemp + sSessionID))).Replace("-", "").ToLower(); After beating my head against a wall long enough I was able to come up with this, and it does spit out the exact same hash as the existing php code. This should allow anyone to generate a hash for logging into most SMF powered message boards (They seem to have a niche market in games and mods on a global scale

      E Offline
      E Offline
      Ennis Ray Lynch Jr
      wrote on last edited by
      #2

      Maybe it should be

      byte[] sResult = sha.ComputeHash(StrToByteArray(sName + sPassword));
      byte[] sSessionResult =sha.ComputeHash(StrToByteArray(sSessionID));
      byte[] returnResult = bew byte[sResult.length + sSessionResult.length];
      Array.Copy(sResult, returnResult , 0, sResult.length);
      Array.Copy(sSessionResult, returnResult , sResult.length, sSessionResult.length);
      sResult = returnResult ;

      Fix the compile errors because I just typed this in but I don't think your .NET code matches the PHP code.

      Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups