Tôi cần xác thực dựa vào bảng thành viên ASP.NET trong php. Api thành viên được cấu hình để sử dụng mật khẩu băm.Sử dụng tư cách thành viên ASP.NET trong PHP
Ai đó có thể cho tôi php để băm mật khẩu đến từ biểu mẫu đăng nhập và so sánh nó với trường sql không?
Tôi biết mật khẩu mà tôi đang chuyển vào là đúng, nhưng nó không bị băm như cũ.
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;
}
}
UPDATE:
Tôi đã thử mã hóa khác nhau với kết quả tương tự. UTF-7, UTF-8 và UTF-16.
CẬP NHẬT: Tôi đã chiến đấu trong vòng một tuần nay. Bounty đến ngay lập tức ...
Đây là mã .net ở dạng thử nghiệm đơn vị. Các bài kiểm tra đơn vị hoạt động và các giá trị được thẳng ra khỏi cơ sở dữ liệu. Bản dịch chính xác của mã này là gì?
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);
}
Bạn có nhận được các giá trị băm khác nhau không? – MyStream
Có, băm không khớp với – Darthg8r
Điều này có thể hữu ích: http://thekindofme.wordpress.com/2008/12/04/aspnet-membership-password-hashing-algorithm/ – Prescott