views:

167

answers:

3

How do I migrate users from a existing users table to Forms Authentication?

There seems to be three options:

  1. T-SQL - Iterate through the existing users table and insert into Forms Authentication tables using the stored procedure aspnet_Membership_CreateUser

  2. Code - create a utility that will iterate through the existing users table and insert into Forms Authentication tables using Membership.CreateUser()

  3. Code - as users login verify credentials against existing users table and insert into Forms Authentication tables using Membership.CreateUser()

Which is the most practical?

I have been currently trying option 1 but I am running into difficulties using the password salt to create the encrypted password from a plain text password

A: 

Have you considered implementing your own MembershipProvider class that hits only your user table?

Trying to synchronise data between two tables may seem trivial now, but may cause you a whole world of hurt in the future as your software evolves.

Christian Hayter
Hello, I would like to migrate in order to take advantage of the Forms Authentication tables that are generated and utilised within ASP.Net MVC to handle log in.
Nicholas Murray
A: 

Just to confirm are you saying you've got an existing users table in your database and you want to use asp.net membership and the membership tables generated?

If that is the case you don't necessarily need to migrate your data. You could extend the membership provider and create your own membership that links into the existing table you already have.

Here's a couple of link if it helps:

Asp.net video

Writing A Custom Membership Provider

Simon G
+1  A: 

With regard to #1, what exactly is the problem? You don't need to worry about the hashing if you've got plaintext passwords already. Just call CreateUser(username, password). Simple as that.

Bryan
Yes I agree. I have gone for step 2. Create a utility and let Membership.CreateUser() do the work.
Nicholas Murray