ValidateUser() public static méthode

public static ValidateUser ( string username, string password ) : bool
username string
password string
Résultat bool
Exemple #1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (IsPostBack)
     {
         var loginVm = new LoginVm();
         if (TryUpdateModel(loginVm, new FormValueProvider(ModelBindingExecutionContext)) &&
             (UserManager.ValidateUser(loginVm.Username, loginVm.Password) && ModelState.IsValid))
         {
             FormsAuthentication.RedirectFromLoginPage(loginVm.Username, false);
         }
     }
     else if (Request.IsAuthenticated)
     {
         Response.StatusCode      = 403;
         Response.SuppressContent = true;
         Context.ApplicationInstance.CompleteRequest();
     }
 }
        protected void User_Login_Authenticate(object sender, AuthenticateEventArgs e)
        {
            var            Logins = sender as System.Web.UI.WebControls.Login;
            MembershipUser User   = Members.GetUser(Logins.UserName);

            if (Members.ValidateUser(User_Login.UserName, User_Login.Password) == true)
            {
                String Role = "";

                if (HttpContext.Current.User.IsInRole("Administrator"))
                {
                    Role = "Administrator";
                }
                if (HttpContext.Current.User.IsInRole("Manager"))
                {
                    Role = "Manager";
                }
                if (HttpContext.Current.User.IsInRole("Users"))
                {
                    Role = "Users";
                }

                var        ticket = new FormsAuthenticationTicket(1, User_Login.UserName, DateTime.Now, DateTime.Now.AddMinutes(2880), User_Login.RememberMeSet, Role, FormsAuthentication.FormsCookiePath);
                String     hash   = FormsAuthentication.Encrypt(ticket);
                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);

                if (ticket.IsPersistent)
                {
                    cookie.Expires = ticket.Expiration;
                }

                DateTime Last_Login = User.LastLoginDate;

                Response.Cookies.Add(cookie);
                Session["Status"]    = true;
                Session["LastLogin"] = Last_Login;
                Response.Redirect(FormsAuthentication.GetRedirectUrl(User_Login.UserName, User_Login.RememberMeSet));
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Invalid login details.');", true);
            }
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (IsPostBack)
     {
         string user   = Request["userName"];
         string pass   = Request["pass"];
         string action = Request["action"];
         if (action == "login" && UserManager.ValidateUser(user, pass))
         {
             FormsAuthentication.RedirectFromLoginPage(user, false);
         }
         else
         {
             message.Style["visibility"] = "visible";
         }
     }
     else if (Request.IsAuthenticated)
     {
         Response.StatusCode      = 403;
         Response.SuppressContent = true;
         Context.ApplicationInstance.CompleteRequest();
     }
 }