开发者

Using Email Address to login - Membership API

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?


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 CreatedUser event. For example, you could do something like this:

MembershipUser currentUser = Membership.GetUser();
currentUser.Email = currentUser.UserName;
Membership.UpdateUser(currentUser);

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


I like using my email address for login name. It generally works very well because I don't have to remember a login for a particular site, and no one else should be using my email address.

But... In addition to Tenaciouslmpy's answer, the other down side is that you then have to be careful about exposing these "usernames". What you'll end up doing is creating some field called "Display Name". Which is totally fine, but just be aware that it's not going to save you any work in the long run to do this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜