简体   繁体   English

在ASP.NET成员身份中哈希密码

[英]Hashing passwords in ASP.NET membership

I have this ASP.NET application that is running fine. 我有这个运行良好的ASP.NET应用程序。 Now I need to add users to the ASP.NET membership database from a Windows Forms application. 现在,我需要从Windows Forms应用程序将用户添加到ASP.NET成员资格数据库。 I've been able to use the Membership classes from inside the Windows forms app successfully, but it takes too long to add a user and I have to add a large amount of users. 我已经能够从Windows窗体应用程序内部成功使用Membership类,但是添加用户花费的时间太长,而且我必须添加大量用户。

So, I´ve been trying to add those users directly to the database, but can´t get the passwords hashed correctly. 因此,我一直在尝试将那些用户直接添加到数据库中,但是无法正确获得哈希值。

Here is the code I'm using to generate the hashed passwords: 这是我用来生成哈希密码的代码:

public static string EncodePassword2(string pass, out string saltb64)
{
    saltb64 = Crypto.GenerateSalt();
    byte[] bytes = Encoding.Unicode.GetBytes(pass);
    byte[] src = Convert.FromBase64String(saltb64);
    byte[] dst = new byte[src.Length + bytes.Length];
    Buffer.BlockCopy(src, 0, dst, 0, src.Length);
    Buffer.BlockCopy(bytes, 0, dst, src.Length, bytes.Length);
    HashAlgorithm algorithm = HashAlgorithm.Create("HMACSHA256");
    byte[] inArray = algorithm.ComputeHash(dst);
    return Convert.ToBase64String(inArray);
}

Does anyone know how to do this the right way? 有谁知道如何正确地做到这一点?

Use Crypto.HashPassword method 使用Crypto.HashPassword方法

Refer this link: 参考此链接:

http://www.troyhunt.com/2012/07/stronger-password-hashing-in-net-with.html http://www.troyhunt.com/2012/07/stronger-password-hashing-in-net-with.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM