Dar*_*g8r 5 php asp.net asp.net-membership
我需要在php中对ASP.NET成员资格表进行身份验证.成员资格api配置为使用散列密码.
有人可以给我php来哈希来自登录表单的密码并将其与sql字段进行比较吗?
我知道我传入的密码是正确的,但它没有相同的哈希值.
private function Auth( $username, $password )
{
// Hashed password in db
$hash = $this->parent->_memberData['conv_password'];
// password passed from form
$bytes = mb_convert_encoding($password, 'UTF-7');
// Salt from db
$salt = base64_decode($this->parent->_memberData['misc']);
// hash password from form with salt
$hashedpassword = base64_encode(sha1($salt . $bytes, true));
// Test em out
if ($hashedpassword == $hash)
{
$this->return_code = "SUCCESS";
return true;
}
else
{
$this->return_code = "WRONG_AUTH";
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
更新:
我尝试了不同的编码,结果相同.UTF-7,UTF-8和UTF-16.
更新: 我一直在争夺这一周.赏金来了......
这是单元测试形式的.net代码.单元测试工作,值直接来自数据库.这段代码到php的正确翻译是什么?
public void EncodePassword()
{
string expected = "aP/mqBu3VkX+rIna42ramuosS3s=";
string salt = "urIaGX0zd/oBRMDZjc1CKw==";
string pass = "Comeonman";
byte[] bytes = Encoding.Unicode.GetBytes(pass);
byte[] numArray = Convert.FromBase64String(salt);
byte[] numArray1 = new byte[(int)numArray.Length + (int)bytes.Length];
byte[] numArray2 = null;
Buffer.BlockCopy(numArray, 0, numArray1, 0, (int)numArray.Length);
Buffer.BlockCopy(bytes, 0, numArray1, (int)numArray.Length, (int)bytes.Length);
HashAlgorithm hashAlgorithm = HashAlgorithm.Create("SHA1");
if (hashAlgorithm != null)
{
numArray2 = hashAlgorithm.ComputeHash(numArray1);
}
Assert.AreEqual(Convert.ToBase64String(numArray2), expected);
}
Run Code Online (Sandbox Code Playgroud)
$password = 'Comeonman';
$salt = base64_decode('urIaGX0zd/oBRMDZjc1CKw==');
$utf16Password = mb_convert_encoding($password, 'UTF-16LE', 'UTF-8');
echo base64_encode(sha1($salt.$utf16Password, true));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1638 次 |
| 最近记录: |