Making Transferring User Passwords Between Instances a Little Faster

Part of my Sitecore upgrade projects this year is to copy data from the old instance to the new ones. One of those tasks will be to copy Users, and of course, their passwords. You've probably seen Sitecore's ASPX file which allows you to transfer User passwords between Sitecore instances. This is needed since Users that are exported/imported will have their passwords scrambled or set to “b”. The tool only allows for one User to be selected at a time, but this small tweak let's you choose a limitless number of Users at a time. 


How the Page Works

Navigate to /sitecore/admin/TransferUserPasswords.aspx once logged in to the Sitecore interface in your CM instance. Looking at the screenshot below, you can see that the connection strings must be completed for both the old and new instances. Once this is done you can select Users from the left and click the arrow to add them on the right. Once all Users are selected you can click Transfer, which will copy their passwords to the new instance. Simple enough, but tedious when you have dozens or more Users to copy.



How to Make it Easier

You can get an updated version of this file here, which will let you multiselect the users, requiring only a single click on the arrows to send them to the right side. 


What Changed?

First, both asp:ListBox fields have the following addition, which will allow multiple selections:

SelectionMode="Multiple"

Next, the button click actions have been changed to iterate over the selections, so they accommodate the multiple choices. Here is an example of the Add action, which has the same changes in the Remove button's action:


Original Add

The selected item checked that it's not null then sent over to the add column.

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        System.Web.UI.WebControls.ListItem listItem = lbUsersIntersect.SelectedItem;
        if (listItem != null)
        {
            ClearListBoxSelection();
            lbTransferPasswords.Items.Add(listItem);
            lbUsersIntersect.Items.Remove(listItem);
        }
    }


Updated Add

You can see there is now a loop where all selected Users are passed over.

    protected void btnAdd_Click(object sender, EventArgs e)
    {
        var selectedItems = new List<ListItem>();
        foreach (ListItem item in lbUsersIntersect.Items)
        {
            if (item.Selected)
            {
                selectedItems.Add(item);
            }
        }
        foreach (ListItem selectedItem in selectedItems)
        {
            lbTransferPasswords.Items.Add(selectedItem);
            lbUsersIntersect.Items.Remove(selectedItem);
        }
        ClearListBoxSelection();
    }


I'm Waiting! What's Going On?

I came back to this after trying it out, and found one improvement that could be made. Logging! 

When transferring hundreds of Users there's no progress from the interface or logs. You just watch ant wait. I've added logging to the page so progress can be monitored during execution:

596 16:04:35 INFO  Password has been udpated for User testuser1@nothing.com. This is User 1 of 498.
596 16:04:35 INFO  Password has been udpated for User testuser2@nothing.com. This is User 2 of 498.
596 16:04:35 INFO  Password has been udpated for User testuser3@nothing.com. This is User 3 of 498.
596 16:04:35 INFO  Password has been udpated for User testuser4@nothing.com. This is User 4 of 498.

This is just a mock. I didn't actually create 500 test Users. :)


Hopefully this helps any teams out there going through similar efforts.