Reputation: 1887
UserManager in Asp.Net Identity 2 prevents creation user with duplicate username through additional request to database to find possible duplicate. I think this is error prone and can cause concurrency errors. The correct mechanism should rely on on unique constraints or indexes. Am I wrong and do I miss something?
Links to source: CreateAsync and ValidateUserName
Upvotes: 1
Views: 3817
Reputation: 35126
No, you are not wrong. And Identity adds the unique index on Username column:
And the migration code for this table is:
CreateTable(
"dbo.AspNetUsers",
c => new
{
Id = c.String(nullable: false, maxLength: 128),
/* .... SNIP .... */
UserName = c.String(nullable: false, maxLength: 256),
})
.PrimaryKey(t => t.Id)
.Index(t => t.UserName, unique: true, name: "UserNameIndex");
Unique index is clearly set on the column.
p.s. you are looking on Identity v3 - it is not released. Current Identity v2.1 is not open source yet.
Upvotes: 3