Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Require unique phone number in Asp.Net Core Identity

In Asp.Net Core Identity framework, I can easily require a unique email address by setting RequireUniqueEmail = true.

Is there any way to do the same for the user's phone number? Note that I don't want to require a confirmed phone number to sign in. The user is not required to enter a phone number but if they do, it must be unique.

like image 457
Simon Christiansen Avatar asked Jan 04 '18 19:01

Simon Christiansen


1 Answers

The easiest way might be to simply search for the phone number in your controller...

bool IsPhoneAlreadyRegistered = _userManager.Users.Any(item => item.PhoneNumber == model.PhoneNumber);
like image 127
Separation of Concerns Avatar answered Nov 15 '22 10:11

Separation of Concerns