[英]Using C# to authenticate against a vBulletin database
我整天都在尋找解決問題的方法,最后決定發帖尋求幫助。 我真的不知道這是否是發布此信息的最佳地點,但也許有人可以幫助我。
因此,我試圖在C#中創建一個簡單的登錄表單,從數據庫中獲取用戶名,MD5(password)和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']), '')
發現了這一點,但仍然不知道如何實現,因此我可以嘗試在C#中重現它。
最好的問候,Magg
給定代碼的格式(忽略它可能會破壞語法):
$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)
相匹配-使用該工具時,請確保您提供的是純文本密碼,而不是數據庫中的哈希。
YMMV。
因此,這是解決我的問題的方法,最終我設法使它起作用。
問題是C#使用所有字符串作為unicode,而vbulletin使用所有字符串作為UTF8
為了進行測試,我創建了一個新表單,添加了一個新的文本框和一個按鈕。 無論如何這都不連接到數據庫,我提供了直接從數據庫中獲取的鹽。(為了測試)
由於已經聲明了vbulleting登錄,如下所示: md5(md5(password)+ salt)
因此,要在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為您解決的所有問題提供了幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.