How to create a asp.net membership provider hashed password manually?

前端 未结 4 1500
执笔经年
执笔经年 2020-12-08 12:36

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.

4条回答
  •  余生分开走
    2020-12-08 12:50

    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();
    }
    

    And the app.config:

    
    
        
            
        
        
            
                
                    
                    
                
            
        
    
    

提交回复
热议问题