AuthenticationService's login() Method Example

Listing 1. Using the AuthenticationService class's login() method to a log a user into a site using an asynchronous postback operation.

function Login() {
  var uid = $get("txtUserName").value;
  var pwd = $get("txtPassword").value;
  Sys.Services.AuthenticationService.login(
   uid,pwd,false,null,null,
   OnLoginCompleted,OnLoginFailure,null);
}

function OnLoginCompleted(isValid,userContext, methodName) {
  if (isValid) {
    alert("You logged in!");
  }
  else {
    alert("Login failed.");
  }
}

function OnLoginFailure(error, userContext, methodName)
{
  alert("Attempt failed: " + error.get_message());
}