Using PHP to authenticate users in an ASP.NET membership

怎甘沉沦 提交于 2019-12-05 14:14:08
silkfire

I took a look at the authentication question page that you linked to and one particular answer captured my attention: https://stackoverflow.com/a/4227642/633098.

Because you said that the algorithm used no longer was SHA1 but more probably SHA256 I started experimenting with HMAC hash, SHA256 instead. It didn't work at first but then I tried using both the concatenated string consisting of the password and the salt in conjunction with the salt (= key) itself, and it worked.

Here's the simple function I made:

function _hash($password, $salt) {
    return base64_encode(hash_hmac('sha256', base64_decode($salt) . iconv('UTF-8', 'UTF-16LE', $password), base64_decode($salt), true));
}

$salt = 'Mu1tp8XzfKl8dSTVAZm44A=='; // Straight from the DB
$password = 'testing';

var_dump(_hash($password, $salt));

Resulting hash: TQN7m8OWIyBOKVwzegWSUBVq7o7+KWFBc46J+B77mLw=

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!