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.
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;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With