如何手动创建一个 asp.net 会员提供商散列密码? [英] How to create a asp.net membership provider hashed password manually?
问题描述
我使用网站作为前端,所有用户都通过标准 ASP.NET 成员资格提供程序进行身份验证.密码以散列"形式保存在 SQL 数据库中.
I'm using a website as a frontend and all users are authenticated with the standard ASP.NET Membership-Provider. Passwords are saved "hashed" within a SQL-Database.
现在我想编写一个具有管理功能的桌面客户端.除其他外,应该有一种方法可以重置用户密码.我可以使用保存的会员数据访问数据库,但是如何手动创建密码盐和哈希?使用 System.Web.Membership 命名空间似乎不合适,所以我需要知道如何手动创建新密码的 salt 和 hash.
Now I want to write a desktop-client with administrative functions. Among other things there should be a method to reset a users password. I can access the database with the saved membership-data, but how can I manually create the password-salt and -hash? Using the System.Web.Membership Namespace seems to be inappropriate so I need to know how to create the salt and hash of the new password manually.
专家们加油!:)
推荐答案
您绝对可以在控制台或 winforms 应用程序中使用 System.Web.Security
.
You can absolutely use System.Web.Security
within a console or winforms app.
这是一个简单的控制台应用程序:
Here's a simple console application:
static void Main(string[] args)
{
MembershipProvider provider = Membership.Provider;
MembershipUser myUser = provider.GetUser("myUser", false);
if( myUser != null ) provider.DeleteUser("myUser", true);
MembershipCreateStatus status;
myUser = provider.CreateUser("myUser", "password", "user@example.com", null, null, true, null, out status);
if (status != MembershipCreateStatus.Success)
{
Console.WriteLine("Could not create user. Reason: " + status.ToString());
Console.ReadLine();
return;
}
Console.WriteLine("Authenticating with "password": " + provider.ValidateUser("myUser", "password").ToString());
string newPassword = myUser.ResetPassword();
Console.WriteLine("Authenticating with "password": " + provider.ValidateUser("myUser", "password").ToString());
Console.WriteLine("Authenticating with new password: " + provider.ValidateUser("myUser", newPassword).ToString());
Console.ReadLine();
}
还有 app.config:
And the app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="MyConnectionString" connectionString="Data Source=localhost;Initial Catalog=MyDatabase;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
<system.web>
<membership defaultProvider="MyMembershipProvider">
<providers>
<clear />
<add name="MyMembershipProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="MyConnectionString"
applicationName="MyApplication"
minRequiredPasswordLength="5"
minRequiredNonalphanumericCharacters="0"
requiresQuestionAndAnswer="false" />
</providers>
</membership>
</system.web>
</configuration>
这篇关于如何手动创建一个 asp.net 会员提供商散列密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!