Skip to content

Instantly share code, notes, and snippets.

@khurramkhang
Last active December 18, 2023 12:32
Show Gist options
  • Save khurramkhang/f9110994e6dd771db87e0e26a394c557 to your computer and use it in GitHub Desktop.
Save khurramkhang/f9110994e6dd771db87e0e26a394c557 to your computer and use it in GitHub Desktop.
Migrate Users to ASP.Net Identity
select * from [dbo].[Users]
INSERT INTO AspNetUsers(Id,
UserName,
Email,
PasswordHash,
SecurityStamp,
EmailConfirmed,
PhoneNumber,
PhoneNumberConfirmed,
TwoFactorEnabled,
LockoutEndDateUtc,
LockoutEnabled,
AccessFailedCount,
IsApproved,
IsLockedOut,
LastLoginDate,
LastLockoutDate,
Comment,
CreationDate)
SELECT
[dbo].[Users].UserId,
[dbo].[Users].UserName,
[dbo].[Memberships].Email,
([dbo].[Memberships].Password+'|'+CAST([dbo].[Memberships].PasswordFormat as varchar)+'|'+[dbo].[Memberships].PasswordSalt),
NewID(),
'true',
NULL,
'false',
'false',
[dbo].[Memberships].LastLockoutDate,
'true',
'0',
[dbo].[Memberships].IsApproved,
[dbo].[Memberships].IsLockedOut,
[dbo].[Memberships].LastLoginDate,
[dbo].[Memberships].LastLockoutDate,
[dbo].[Memberships].Comment,
[dbo].[Memberships].CreateDate
FROM [dbo].[Users]
INNER JOIN [dbo].[Memberships] ON [dbo].[Memberships].ApplicationId = [dbo].[Users].ApplicationId
AND [dbo].[Users].UserId = [dbo].[Memberships].UserId;
insert into [dbo].AspNetRoles (Id,Name) select RoleId, RoleName from [dbo].Roles
insert into [dbo].AspNetUserRoles(RoleId, UserId) select RoleId, UserId from [dbo].UsersInRoles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment