Creating ASP.NET Identity user using SQL

6k views Asked by At

In our ASP.NET MVC Core app we are using ASP.NET Idenity to implement user management.

Question: Instead of using ASP.NET user interface, how can we directly create a user into the SQL Database (using a SQL statement etc.)? Will creating a user directly in ASPNETUsers table cause any issue? Note: We need to populate built-in identity table ASPNETUsers from a list of users. Password can be anything and no specific role is required.

1

There are 1 answers

1
Michael Wheeler On

Here is the insert script for AspNetUsers

INSERT [dbo].[AspNetUsers] ([Id], [AccessFailedCount], [ConcurrencyStamp], 
[Email], [EmailConfirmed], [LockoutEnabled], [LockoutEnd], [NormalizedEmail], 
[NormalizedUserName], [PasswordHash], [PhoneNumber], [PhoneNumberConfirmed], 
[SecurityStamp], [TwoFactorEnabled], [UserName]) VALUES 
(N'0633e088-30a6-444f-9603-70d7c26748ef', 0, 
N'd2feada1-c7db-4f5a-801c-4ae5c990a49d', N'[email protected]', 1, 1, NULL, 
N'[email protected]', N'[email protected]', 
N'AQAAAAEAACcQAAAAEBqhdvkH3O3glua9IFU+LDamc3mj03dPQ/8brAW34GTN6kxMOqs5je90FNn7fuNleQ==', 
N'+10001234567', 1, N'6123adf0-fc53-4abb-b6a4-52d164da4e4f', 0, N'[email protected]')
GO

Of course you will need to generate your own Guids and hash your own password.