C#  •  Validate Users

Listing 5. ASP.NET 2 includes a new Membership object that allows your application to validate, create, and change users. You can write custom membership providers in more advanced scenarios to leverage other data stores.

void ctlLogin_Authenticate(object sender,   
   System.Web.UI.WebControls.
   AuthenticateEventArgs e) {
   if (Membership.ValidateUser(
      this.ctlLogin.UserName, 
      this.ctlLogin.Password)) { 
      e.Authenticated = true;
      FormsAuthentication.SetAuthCookie(
         this.ctlLogin.UserName, 
         this.ctlLogin.RememberMeSet);
      if (Request.QueryString["ReturnUrl"] != 
         null) {
         Response.Redirect(Request.QueryString[
            "ReturnUrl"].ToString());
      }
      else {
         Response.Redirect("Default.aspx");
      }
   }
}