【问题标题】:Asp.net Membership-How to match security answer explicitly?Asp.net Membership-如何明确匹配安全答案?
【发布时间】:2011-02-04 11:47:19
【问题描述】:

我需要匹配用户输入的安全答案和存储在 aspnet_Membership 表中的安全答案。 我不想使用 resetpassword("Securityanswer") 方法来验证用户。

有没有办法加密输入的安全答案或解密存储的安全答案。

谢谢。

【问题讨论】:

    标签: asp.net-membership


    【解决方案1】:

    /将输入的秒数转换为字节数组/

                Dim bytes As Byte() = Encoding.Unicode.GetBytes(secAns)
    

    /将您的密钥转换为 base 64 字符串以获得原始密码非常重要。/

                Dim src As Byte() = Convert.FromBase64String(key) 
    
                /*Concatenate sec ans and hash key*/
    
                Dim dst As Byte() = New Byte(src.Length + (bytes.Length - 1)) {}
    
                Buffer.BlockCopy(src, 0, dst, 0, src.Length)
                Buffer.BlockCopy(bytes, 0, dst, src.Length, bytes.Length)
    
                /*Create algo object for SHA1*/
    
                Dim algorithm As HashAlgorithm = HashAlgorithm.Create("SHA1")
    
                /*Compute hash value of concatenated ans and key*/
    
                Dim inArray As Byte() = algorithm.ComputeHash(dst)
    
                /*Convert hashed ans back to string*/
    
                Dim hashedAns As String = Convert.ToBase64String(inArray)
    

    【讨论】:

      【解决方案2】:

      我知道这有点老了......但我无法让任何已发布的这个问题的答案起作用,但我通过反复试验发现“安全答案”的存储类似于密码的存储方式(如果您将密码设置为哈希)。我能够使用以下关于密码的帖子的答案来实现上述原始问题的目标: ASP.NET Membership C# - How to compare existing password/hash

      我刚刚使用了数据库中密码中的盐,它就像一个魅力。希望这可以帮助其他人连续几天拔头发。

      【讨论】:

        【解决方案3】:

        无法解密存储在成员资格表中的安全答案。 您可以对收到的答案进行哈希处理,然后将其与存储在数据库中的哈希值进行比较。 为此使用 FormsAuthentication.HashPasswordForStoringInConfigFile ..

        【讨论】:

        • 您好,感谢 rply.FormsAuthentication.HashPasswordForStoringInConfigFile 接受两个参数。您能告诉我要传递什么参数吗?
        • 第一个参数是您要散列的密码,第二个参数是您要使用的散列技术。更多详情请见:msdn.microsoft.com/en-us/library/… 如果您觉得答案有用,请将其标记为答案。 :)
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-26
        • 1970-01-01
        • 2012-01-12
        相关资源
        最近更新 更多