我正在使用爲ASP.NET創建的存在數據庫的新PHP項目。我無法訪問ASP源代碼,所以我不知道密碼是如何散列的。在ASP中讀取ASP哈希密碼
我只需要一種方法來比較用戶從PHP登錄到數據庫中存儲的密碼,所以現有的用戶(和新的ASP腳本寄存器)不必爲這兩個腳本創建兩個密碼。
我知道他們已經被sha1/base64形式哈希了,但研究讓我意識到ASP.NET使用SqlMembershipProvider或者membershipprovider生成SALT,這是我的問題。
我需要一種方法來使PHP驗證ASP哈希密碼。
UPDATE 1:
這是來自數據庫的哈希密碼,用於測試用戶: AHmLnE/qf1Jb9ABf6uIHEomuQCN8e0Xt8Bpl8Ty4fzdicsnut6nK/Rv/ZlfJDOK9Pg==
密碼1234
更新2:
在嘗試@DeadSpace的答案後,我結束了這個(不工作):
<?php
include "SymmetricEncryption.php";
$hash = "AHmLnE/qf1Jb9ABf6uIHEomuQCN8e0Xt8Bpl8Ty4fzdicsnut6nK/Rv/ZlfJDOK9Pg=="; // password is : 1234
echo "Hashed: ". $hash . "<br>";
$salt = substr(base64_decode($hash), 0, 16);
//$salt = substr(base64_decode($hash), 1, 16); // C# = Buffer.BlockCopy(src, 1, dst, 0, 16);
$hasher = new SymmetricEncryption();
echo "Class test: ". base64_encode($salt. $hasher->encrypt('', '1234', $salt)) . "<br>";
/***** another faield approach *****/
//Not working either :(
echo "another way: ". base64_encode($salt. pbkdf2('SHA1', '1234', $salt, 1000, 32, true)) ;
function pbkdf2($algorithm, $password, $salt, $count, $key_length, $raw_output = false)
{
$algorithm = strtolower($algorithm);
if(!in_array($algorithm, hash_algos(), true))
trigger_error('PBKDF2 ERROR: Invalid hash algorithm.', E_USER_ERROR);
if($count <= 0 || $key_length <= 0)
trigger_error('PBKDF2 ERROR: Invalid parameters.', E_USER_ERROR);
if (function_exists("hash_pbkdf2")) {
// The output length is in NIBBLES (4-bits) if $raw_output is false!
if (!$raw_output) {
$key_length = $key_length * 2;
}
return hash_pbkdf2($algorithm, $password, $salt, $count, $key_length, $raw_output);
}
$hash_length = strlen(hash($algorithm, "", true));
$block_count = ceil($key_length/$hash_length);
$output = "";
for($i = 1; $i <= $block_count; $i++) {
// $i encoded as 4 bytes, big endian.
$last = $salt . pack("N", $i);
// first iteration
$last = $xorsum = hash_hmac($algorithm, $last, $password, true);
// perform the other $count - 1 iterations
for ($j = 0; $j < $count; $j++) {
$xorsum ^= ($last = hash_hmac($algorithm, $last, $password, true));
}
$output .= $xorsum;
}
if($raw_output)
return substr($output, 0, $key_length);
else
return bin2hex(substr($output, 0, $key_length));
}
輸出:
Hashed: AHmLnE/qf1Jb9ABf6uIHEomuQCN8e0Xt8Bpl8Ty4fzdicsnut6nK/Rv/ZlfJDOK9Pg==
Class test: AHmLnE/qf1Jb9ABf6uIHEmNZcjhUOFMxREhQOGQrTFMzb0VpL2c9PQ==
another way: AHmLnE/qf1Jb9ABf6uIHEp3Abm4NCdtNaQ/iXjxShfVK9SDoAiCfYJ7Pbz0UUnDZ
那麼這肯定是一個問題。除非你知道他們如何散列密碼,似乎你最好的選擇是重置所有的用戶密碼並重新散列它並保存在數據庫中 – zimorok
這樣可以防止asp驗證新的散列密碼!我猜!。 – Dohab
那裏你有它,除非你知道ASP方面的散列函數,從PHP做它是不可能的。 – zimorok