使用C#对vBulletin数据库进行身份验证

时间:2013-06-29 21:01:07

标签: c# login passwords salt vbulletin

我花了一整天时间寻找解决问题的方法,最后决定发帖寻求帮助。 我真的不知道这是否是发布此帖的最佳地点,但也许有人可以帮助我。

所以我试图在C#中创建一个简单的登录表单 从数据库中获取用户名,MD5(密码)和salt一切正常。现在我的问题是如何从我的表单输入密码+ salt进行比较。我不知道当用户在论坛上创建一个帐户时,vbulleting如何存储密码,我也不知道他如何生成一个盐,如果它是随机的,或用户名基数,以及他采取了多少次迭代。

任何人都可以帮助我吗?

编辑: -

$vbulletin->userinfo['password'] != iif($password AND !$md5password, md5(md5($password) . $vbulletin->userinfo['salt']), '') AND
            $vbulletin->userinfo['password'] != iif($md5password, md5($md5password . $vbulletin->userinfo['salt']), '') AND
            $vbulletin->userinfo['password'] != iif($md5password_utf, md5($md5password_utf . $vbulletin->userinfo['salt']), '')

发现了,但仍然不知道他们是如何制作的,所以ican尝试在c#中重现它

最诚挚的问候, MAGG

2 个答案:

答案 0 :(得分:0)

给定代码,格式化(并忽略这可能会破坏语法):

    $vbulletin->userinfo['password'] != iif($password AND !$md5password,
        md5(md5($password) . $vbulletin->userinfo['salt']), '')
AND $vbulletin->userinfo['password'] != iif($md5password,
        md5($md5password . $vbulletin->userinfo['salt']), '')
AND $vbulletin->userinfo['password'] != iif($md5password_utf,
        md5($md5password_utf . $vbulletin->userinfo['salt']), '')

这个表达式检测到“所有方法都失败了”,但是因为我发现难以阅读,所以让我们通过将De Morgan用于隐含的外部否定来重写它作为“任何方法成功”的正面匹配:

    $vbulletin->userinfo['password'] == iif($password AND !$md5password,
        md5(md5($password) . $vbulletin->userinfo['salt']), '')
OR  $vbulletin->userinfo['password'] == iif($md5password,
        md5($md5password . $vbulletin->userinfo['salt']), '')
OR  $vbulletin->userinfo['password'] == iif($md5password_utf,
        md5($md5password_utf . $vbulletin->userinfo['salt']), '')

现在,应用简化和注意,并iff(x,y,z)的工作方式与x?y:z类似,我们最终会得到类似C#中的以下内容:

   storedPW == password && !md5password ? md5(md5(password) + salt) : ''
|| storedPW == md5password ? md5(md5password + salt) : ''
|| storedPw == md5password_utf ? md5(md5password_utf + salt) : ''

检查有点难看,但..不是我的代码。要实现的重要一点是模式是:

 md5(md5(password) + salt) -> storedPw

不幸的是,匹配来自insidepro链接的md5(md5($pass).$salt) - 使用该工具时,请确保您提供纯文本密码而不是来自数据库的哈希。

因人而异。

答案 1 :(得分:0)

所以继承问题的解决方案,最后我设法让它发挥作用。

问题是C#使用所有字符串作为unicode,而vbulletin使用所有字符串作为UTF8

为了测试,我创建了一个新表单,添加了一个新文本框和一个按钮。 这无论如何都不要连接到数据库,我直接从数据库中提取盐。(为了测试)

由于已经说过vbulleting logins如下: 的 MD5(MD5(密码)+盐)

因此,要在C#中重现相同的内容,但使用UTF8继承解决方案:

static public string GetMd5Sum(string str)
    {
        //vBulletin uses UTF8 as strings, so you need to pass the user input string as UTF8 also
        Encoder enc = System.Text.Encoding.UTF8.GetEncoder();

        //Create a byte[] array to store the new UTF8 string
        byte[] utf8text = new byte[str.Length];

        //Pass the string to the byte[] array
        enc.GetBytes(str.ToCharArray(), 0, str.Length, utf8text , 0, true);

        //Hash the byte[] array with our UTF8 string inside
        MD5 md5 = new MD5CryptoServiceProvider();
        byte[] result = md5.ComputeHash(utf8text);

        //Build the final string by converting each byte
        //into hex and appending it to a StringBuilder
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < result.Length; i++)
        {
            sb.Append(result[i].ToString("x2")); //x2 here so the outcome result is all in lowercase, couse vbulleting also stores all in lowercase
        }

        //And return it
        return sb.ToString();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        //Get the user input password as plain text
        string pass = textBox1.Text;

        //Here i provided the salt explicit that i took from the database
        string salt = "N1GOt=>8sdO@E54)PH2@NCm5yI#]3u";

        //Here we convert the plain text password into the first hash
        string p1 = GetMd5Sum(pass);

        //Here we add the salt to the previous hashed password
        string p2 = p1 + salt;

        //Here we hash again the previous hashed password + the salt string
        string final = GetMd5Sum(p2);

        //this was just to the test to see if it all works as intended
        MessageBox.Show(final);
    }

这将输出与密码一样存储在数据库中的完全相同的哈希值。

感谢user2246647,感谢您对此问题的所有帮助。