allBlogsList

Quick way to Transfer User Accounts

In some cases, we might have a need to transfer user accounts between different Sitecore instances that do not use the shared user accounts storage. In this article, I would like to share my experiences and thoughts on how I completed a successful migration.

Username_Password

There are two steps that are involved as part of this transfer,

  1. User Accounts
  2. User Passwords

User accounts can be transferred by using Sitecore packages or by serialization. Once the transfer is complete from source to target instance, you will notice that the migration is pretty easy and quick. However, you won't be able to use any of these accounts to login to Sitecore client or the application.

The reason being, all the transferred users will have their passwords either set to a random value in case of Sitecore packages, or to the default value "b" when using serialization.

Sitecore provided us an option to complete this migration by transferring the passwords as well from Source to Target environments. Please refer to the article listed here

TransferUserpasswordsPage

However, I was having difficulties using this approach in my case due to the following reasons:

  1. You can only select one user at a time
  2. I had a list close to 15,000 users and didn't want to go through them one at a time

I even updated the code logic in the TransferUserPasswords.aspx to allow selection of multiple users. It was still not an option as it was consuming a lot of time for a batch of 100 users at a time.

So, I decided to use a SQL script which can transfer the passwords from Source to Target environment. Thanks to Andrew Lansdowne who saved me a lot of time. The script is as follows:

--BEGIN TRAN

	UPDATE [scTargetCoreDatabase].dbo.aspnet_membership 
	SET 
	  [password] = scSourceMembership.[password],
	  [passwordsalt] = scSourceMembership.[passwordsalt],
	  [islockedout] = scSourceMembership.[islockedout],
	  [isapproved] = scSourceMembership.[isapproved]
	FROM [scTargetCoreDatabase].dbo.aspnet_membership scTargetMembership
		INNER JOIN [scTargetCoreDatabase].dbo.aspnet_users scTargetUsers 
	ON scTargetMembership.userid = scTargetUsers.userid
		INNER JOIN [scSourceCoreDatabase].dbo.aspnet_users scSourceUsers 
	ON scSourceUsers.username COLLATE DATABASE_DEFAULT = scTargetUsers.username COLLATE DATABASE_DEFAULT
		INNER JOIN [scSourceCoreDatabase].dbo.aspnet_membership scSourceMembership 
	ON scSourceUsers.userid = scSourceMembership.userid

--COMMIT TRAN

Source = scSourceCoreDatabase, Target = scTargetCoreDatabase.

This works as expected and I was able to login successfully into the Sitecore client and the application.


Important Notes:

  • Works only if source and target databases are on same server
  • Please make sure you have entered the correct information for Source and Target databases

References: