Search code examples
asp.netmembershipsqlmembershipprovider

How to migrate from custom Membership Provider to SqlMembershipProvider?


I'm currently using a very basic custom implementation of MembershipProvider in an ASP.NET web application. As my requirements for membership increase, it seems to make a lot of sense to use an existing, full featured, and well tested implementation like SqlMembershipProvider. I've figured out how to use the aspnet_Memebership stored procedures to create users from my custom tables, but I'm stuck on the password. My custom implementation doesn't use salt, and SqlMembershipProvider seems to require it.

I want this to be a smooth transition for my users and not require everyone to update their password the first time they login after the change.

How do I migrate hashed passwords from a custom implementation (see below) to SqlMemberhipProvider?

FormsAuthentication.HashPasswordForStoringInConfigFile(password, FormsAuthPasswordFormat.SHA1.ToString())

Update: I should clarify that my custom provider is an implementation of MembershipProvider, just not a full featured one. Also, I've tried using aspnet_Membership_CreateUser with empty salt, but the hashes don't match.


Solution

  • You can write a custom hash algorithm that removes the salt (the first 16 bytes of the combined salt-and-password).

    http://forums.asp.net/t/981295.aspx

    Alternatively you could probably write your own class that inherits MembershipProvider, but this would be more work.