php - 在 PHP 中使用 ASP.NET 成员资格

标签 php asp.net asp.net-membership

我需要根据 PHP 中的 ASP.NET 成员表进行身份验证。成员(member) 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;
    }
}

更新:

我尝试了不同的编码但结果相同。 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);
    }

最佳答案

$password = 'Comeonman';
$salt = base64_decode('urIaGX0zd/oBRMDZjc1CKw=='); 
$utf16Password = mb_convert_encoding($password, 'UTF-16LE', 'UTF-8');
echo base64_encode(sha1($salt.$utf16Password, true));

关于php - 在 PHP 中使用 ASP.NET 成员资格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9407494/

相关文章:

c# - 使用成员表进行代码优先建模

php - Twitter 应用程序开发 : PHP or javascript. ..请帮助

php递归变量不会改变

php - 将 2 个内部联接结果合并为一个结果

php - 多语言网站的最佳数据库模型

生成服务器上的 ASP.NET v5

asp.net - 有没有办法从 Sql Server Management Studio 的过程列表中隐藏架构或至少隐藏 aspnet 过程?

c# - C# 中的 UTC 时间戳(以毫秒为单位)到短日期时间字符串

asp.net - ASP.Net身份-使用自定义架构

asp.net - 同时使用多个 ASP.NET 角色提供程序