Search code examples
c#asp.net-mvcasp.net-membershiplogin-control

How does Membership.ValidateUser method access a database?


I wanted to build a membership system at the beginning of my MVC project and I used Membership.ValidateUser method to verify credentials. However I could not understand how does this method access my database and check my email and password informations.

[HttpPost]
[ActionName("Login")]
public ActionResult Login(LoginModel loginModel)
{
        if (Membership.ValidateUser(loginModel.Email, loginModel.Password))
        {
            FormsAuthentication.SetAuthCookie(loginModel.Email, true);
            return Json(true);
        }

        return new JsonNetResult() 
        { Data = new { Error = true, Messages = new[] { new { Message = "Wrong username or password" } } } };
}

Solution

  • It' used the MembershipProvider specified on your Web.config file to validate the user. By default, it uses DefaultMembershipProvider