【发布时间】:2011-02-04 11:47:19
【问题描述】:
我需要匹配用户输入的安全答案和存储在 aspnet_Membership 表中的安全答案。 我不想使用 resetpassword("Securityanswer") 方法来验证用户。
有没有办法加密输入的安全答案或解密存储的安全答案。
谢谢。
【问题讨论】:
我需要匹配用户输入的安全答案和存储在 aspnet_Membership 表中的安全答案。 我不想使用 resetpassword("Securityanswer") 方法来验证用户。
有没有办法加密输入的安全答案或解密存储的安全答案。
谢谢。
【问题讨论】:
/将输入的秒数转换为字节数组/
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)
【讨论】:
我知道这有点老了......但我无法让任何已发布的这个问题的答案起作用,但我通过反复试验发现“安全答案”的存储类似于密码的存储方式(如果您将密码设置为哈希)。我能够使用以下关于密码的帖子的答案来实现上述原始问题的目标: ASP.NET Membership C# - How to compare existing password/hash
我刚刚使用了数据库中密码中的盐,它就像一个魅力。希望这可以帮助其他人连续几天拔头发。
【讨论】:
无法解密存储在成员资格表中的安全答案。 您可以对收到的答案进行哈希处理,然后将其与存储在数据库中的哈希值进行比较。 为此使用 FormsAuthentication.HashPasswordForStoringInConfigFile ..
【讨论】: