Search code examples
asp.net-mvcasp.net-coreasp.net-identityasp.net-core-identity

Register and Login by Phone Number in Asp.net Core Identity


Is it possible to don't use Email to register and login in asp.net core identity?

Users just register by mobile number and login by SMS verification.


Solution

  • One possible way is to setup identity as two factor authentication. Instead of email use username to store the mobile number. To do this set RequireUniqueEmail = false in ApplicationUserManager.Create.

    You'll need to add your own code to retrieve the number and validate it. Make sure it always has the same format as it should match the username.

    In the code where the username is verified skip the password check (since password is null), but do check the number. Send an SMS with code and continue with the flow.

    You can add your own logic to create and verify the code and how long it is valid.