Specify an email address as the username in ASP.NET.

I want to use the email address as the username in the api membership instead of accepting the username. I want the user to be able to register on my site using the email address, and he can log in using the email id and password instead of the username and password.

+4
source share
3 answers

This is what we have done, so it can be reused and we can register it in the web.config file. If you think about it, this is where he counts. as long as your verification and the external interface indicate to the endpoint that their username should be email and you perform the correct verification ... from there, his usual calls to any member provider support you. A new method for the abridged version and hiding / changing the original behind our facade.

public class EmailAsUsernameMembershipProvider : SqlMembershipProvider { public MembershipUser CreateUser(string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { return base.CreateUser(email, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey, out status); } private new MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status) { return base.CreateUser(email, password, email, passwordQuestion, passwordAnswer, isApproved, providerUserKey, out status); } public override bool RequiresUniqueEmail { get { return true; } } } 
+7
source

This is all possible, as described in this thread already, but there is one thing you need to know about: in the database, the username is 50 characters (table users), while mail (membership in the table) is 256 characters. In fact, this means shorter email addresses. :)

+5
source

Just enter username = user email address.

To do this, simply put the RegEx validator in the user creation form to allow only the correct letter as the user name.

Rename existing usernames according to users email.

+4
source

Source: https://habr.com/ru/post/1346024/


All Articles