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());
}