设置电子邮件地址作为用户名在ASP.NET成员资格提供电子邮件地址、用户名、成员、资格

2023-09-03 02:51:12 作者:陪衬我孤痞

我想使用的电子邮件地址作为用户名的成员资格API,而不是接受一个用户名。  我想,一个用户可以使用电子邮件地址立即登记到我的网站,他可以用电子邮件ID和密码,而不是用户名和密码登录。

I want to use email address as username in membership api instead of accepting a username. I want that a user can signup to my site using email address and he can login using email id and password instead username and password.

推荐答案

这是我们做的,所以它的可重复使用的,我们可以章它在web.config中。如果你想想看,这是它计数。只要你的验证和前端显示给他们的用户名应该是邮件的最终用户,以及你做正确的验证......从那里正常的呼叫到任何成员提供的支持你。新方法的快捷版本,隐藏/改变我们的门面背后的原件。

This is what we did, so its reusable and we can reg it in the web.config. If you think about it, this is where it counts. as long as your validation and frontend indicate to the enduser that their username should be email, and you do proper validation... from there its normal calls to whatever membership provider is backing you. New method for the shortcut version, and hiding/altering 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;
        }
    }
}