By default, Membership API uses a separate username field to login users. I would like to use the email address for users to login. Is this a good idea?
How would I modify the Login, Register a user, Forgot password control to support this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s certainly possible to do this. One way is to alter the CreateUserWizard template and remove the default Email textbox and set EmailRequired to false. Then, change the username label to E-mail. If you use the CreateUserWizard control, then you must keep the textbox ID as UserName otherwise an error will be thrown. You can then access the ‘username’ the same way as usual as the user’s email address will be stored in the username column.
If you want, you could also have the email column filled with the username by handling the
CreatedUserevent. For example, you could do something like this:This way, the email column is also filled for when you want to use Membership methods.
The main downside is that the Membership API doesn’t let you change the username. Therefore, if the user changes their email address, their username will remain as the old email address. In order to fix this, you’ll have to skip the Membership API and go straight to the SQL code. You can find out how to do that here