PhpBBとC#アプリケーションの統合

画像



おやすみなさい!



誰もが過去にフォーラムがどのように人気があったか、そしてもちろんphpBBフォーラムが人気だったことを覚えていると思います。 今日、残念なことに、彼らは社会サービスに道を譲ります。 ネットワーク、しかしまだ完全に別の世界に出発していません。



今日の投稿では、ユーザー認証に関するphpBBとC#アプリケーションの統合方法について説明します。 多くの人がそれに興味を持つとは思いませんが、人がいるように思えます...



開始するには、 \ functions.php含むファイルを開き、関数phpbb_check_hash_hash_crypt_privateおよび_hash_encode64を見つけます。 C#に移植する必要があるのはそれらであり、phpBBでユーザーを認証します。



次のライブラリを接続します。



using System.Security.Cryptography; using System.Text;
      
      







そして、関数を慎重に別の言語に翻訳することから始めます。 私は明らかに、C#で採用されたフォーマットに従って関数と変数の名前を変更しませんでしたが、それらをphpBBと同じままにしました。



  public bool phpbb_check_hash(string password, string hash) { var itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; if (hash.Length == 34) { return (_hash_crypt_private(password, hash, itoa64) == hash) ? true : false; } return (Md5(Encoding.UTF8.GetBytes(password)) == Encoding.UTF8.GetBytes(hash)) ? true : false; }
      
      







  public string _hash_crypt_private(string password, string setting, string itoa64) { var output = "*"; if (setting.Substring(0, 3) != "$H$" && setting.Substring(0, 3) != "$P$") { return output; } var countLog2 = itoa64.IndexOf(setting[3]); if (countLog2 < 7 || countLog2 > 30) { return output; } var count = 1 << countLog2; var salt = setting.Substring(4, 8); if (salt.Length != 8) { return output; } var str = new byte[Encoding.UTF8.GetBytes(salt).Length + Encoding.UTF8.GetBytes(password).Length]; Array.Copy(Encoding.UTF8.GetBytes(salt), 0, str, 0, Encoding.UTF8.GetBytes(salt).Length); Array.Copy(Encoding.UTF8.GetBytes(password), 0, str, Encoding.UTF8.GetBytes(salt).Length, Encoding.UTF8.GetBytes(password).Length); var hash = Md5(str); do { str = new byte[hash.Length + Encoding.UTF8.GetBytes(password).Length]; Array.Copy(hash, 0, str, 0, hash.Length); Array.Copy(Encoding.UTF8.GetBytes(password), 0, str, hash.Length, Encoding.UTF8.GetBytes(password).Length); hash = Md5(str); } while (--count != 0); output = setting.Substring(0, 12); output += _hash_encode64(hash, 16, itoa64); return output; }
      
      







  public string _hash_encode64(byte[] input, int count, string itoa64) { var output = ""; var i = 0; do { int value = input[i++]; output += itoa64[value & 0x3f]; if (i < count) { value |= input[i] << 8; } output += itoa64[(value >> 6) & 0x3f]; if (i++ >= count) { break; } if (i < count) { value |= input[i] << 16; } output += itoa64[(value >> 12) & 0x3f]; if (i++ >= count) { break; } output += itoa64[(value >> 18) & 0x3f]; } while (i < count); return output; }
      
      







  public byte[] Md5(byte[] str) { var md5CryptoServiceProvider = new MD5CryptoServiceProvider(); return md5CryptoServiceProvider.ComputeHash(str); }
      
      







このコードが誰かに役立つかどうかはわかりませんが、一時は多くのフォーラムを調べましたが、このトピックについては何も見つかりませんでした。 それが私がコードを一般に公開することにした理由です。



コメントありがとうございます!



All Articles