简体   繁体   English

如何在空的成员资格表中创建自己的密码?

[英]How I can create my own password in an empty membership table?

I need to create a user in an empty [aspnet_Membership] table. 我需要在空的[aspnet_Membership]表中创建一个用户。

public string EncodePassword(string pass, string salt)
{       
    byte[] bIn = Encoding.Unicode.GetBytes(pass);
    byte[] bSalt = Convert.FromBase64String(salt);
    byte[] bAll = new byte[bSalt.Length + bIn.Length];
    byte[] bRet = null;
    System.Buffer.BlockCopy(bSalt, 0, bAll, 0, bSalt.Length);
    System.Buffer.BlockCopy(bIn, 0, bAll, bSalt.Length, bIn.Length);
    System.Security.Cryptography.HashAlgorithm s = System.Security.Cryptography.HashAlgorithm.Create(Membership.HashAlgorithmType);
    bRet = s.ComputeHash(bAll);          
    return Convert.ToBase64String(bRet);
}

I am using ASP.NET authentication to login but it couldn't login to web site because of wrong password. 我正在使用ASP.NET身份验证登录,但由于密码错误而无法登录网站。

<membership>
  <providers>
    <clear />
    <add name="AspNetSqlMembershipProvider" 
         type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
         connectionStringName="SQLConnectionString"
         enablePasswordRetrieval="false" 
         enablePasswordReset="true" 
         requiresUniqueEmail="false"
         requiresQuestionAndAnswer="false" 
         minRequiredPasswordLength="3" 
         minRequiredNonalphanumericCharacters="0"
         applicationName="eShop"           
         passwordFormat="Hashed" />
  </providers>
</membership>

    password = EncodePassword(password, "asas" + password);    
    string userId = "0";
    SqlCommand c = new SqlCommand();
    c.Connection = con;
    cmd.CommandText = "Select UserId From aspnet_Users Where UserName ='" + username + "'";
    userId = ((int)cmd.ExecuteScalar()).ToString();
    cmd.CommandText = string.Empty;
    c.CommandText = "insert InTo aspnet_Membership ([ApplicationId], [UserId], [Password], [PasswordSalt], [PasswordFormat]) ";
    c.CommandText += "Values (2 , " + userId + ",'" + password + "','" + password + "', 1)";
    c.ExecuteNonQuery();        

and I have a simple asp.net login control How I can do this ? 而且我有一个简单的asp.net登录控件,该怎么办?

Don't try to change the database directly. 不要尝试直接更改数据库。 If you want to add a new user programmatically, use the Membership.CreateUser method. 如果要以编程方式添加新用户,请使用Membership.CreateUser方法。 The method's documentation contains an example with the code you need to write. 该方法的文档包含一个示例,其中包含您需要编写的代码。

Instead of writing the login and registration code yourself you can also use the built-in login controls like the CreateUserWizard control to add a new wizard, the ChangePassword control to change a password etc. 除了自己编写登录和注册代码外,您还可以使用内置的登录控件,例如CreateUserWizard控件来添加新向导,使用ChangePassword控件来更改密码等。

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

相关问题 如何在Visual Studio 2012中在自己的数据库中创建成员资格表 - How Can I Create Membership Tables In My Own Database in Visual Studio 2012 如何创建自己的异常? - How can I create my own exception? 我可以在自己的用户数据库中使用ASP.NET WebForms中的成员资格提供程序吗? 如果是这样,怎么办? - Can I use the Membership provider in ASP.NET WebForms with my own User database? If so, how? 在.NET Web应用程序中,如何在无需托管自己的SQL数据库的情况下实现成员资格? - In a .NET web app, how can I implement Membership without having to host my own SQL database? 如何在我自己的应用程序中的Explore中创建“打开方式”列表 - How can I create a “Open with” list as in Explore in my own application 如何使用SilverLight创建自己的对象类 - How can I create my own class of objects using SilverLight 如何创建自己的表单设计器? - How can I create my own form designer? 如何创建自己的自定义按钮? - How can I create my own custom buttons? 如何为GTK创建自己的样式并在应用程序中实施 - how can I create own style for GTK and enforce it in my application 如何创建自己的ListView UserControl? - How can I create my own ListView UserControl?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM