Exemplo n.º 1
0
        public void AuthenticateWithCode_ValidCode_ReturnsTrue()
        {
            securitySettings.RequireAccountVerification = false;
            var id = subject.CreateAccount("test", "pass", "*****@*****.**").ID;

            subject.ChangeMobilePhoneRequest(id, "123");
            var acct = subject.GetByID(id);

            subject.ChangeMobilePhoneFromCode(id, acct.MobileCode);
            subject.ConfigureTwoFactorAuthentication(acct.ID, TwoFactorAuthMode.Mobile);

            subject.Authenticate("test", "pass");

            acct = subject.GetByID(id);
            Assert.IsTrue(subject.AuthenticateWithCode(id, acct.MobileCode));
        }
Exemplo n.º 2
0
        public ActionResult TwoFactorAuthCodeLogin(string button, TwoFactorAuthInputModel model)
        {
            var ctx = Request.GetOwinContext();
            var id  = ctx.GetIdFromTwoFactorCookie();

            if (id == null)
            {
                // if the temp cookie is expired, then make the login again
                return(RedirectToAction("Index"));
            }

            if (button == "signin")
            {
                if (ModelState.IsValid)
                {
                    BrockAllen.MembershipReboot.UserAccount account;
                    if (userAccountService.AuthenticateWithCode(id.Value, model.Code, out account))
                    {
                        authSvc.SignIn(account);

                        if (userAccountService.IsPasswordExpired(account))
                        {
                            return(RedirectToAction("Index", "ChangePassword"));
                        }

                        if (Url.IsLocalUrl(model.ReturnUrl))
                        {
                            return(Redirect(model.ReturnUrl));
                        }

                        return(RedirectToAction("Index", "AccountHome"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Invalid Code");
                    }
                }
            }

            if (button == "resend")
            {
                ModelState.Clear();
                this.userAccountService.SendTwoFactorAuthenticationCode(this.User.GetUserID());
            }

            return(View("TwoFactorAuthCodeLogin", model));
        }
Exemplo n.º 3
0
        public ActionResult TwoFactorAuthCodeLogin(string button, TwoFactorAuthInputModel model)
        {
            if (!User.HasUserID())
            {
                // if the temp cookie is expired, then make the login again
                return(RedirectToAction("Index"));
            }

            if (button == "signin")
            {
                if (ModelState.IsValid)
                {
                    HierarchicalUserAccount account;
                    if (userAccountService.AuthenticateWithCode(this.User.GetUserID(), model.Code, out account))
                    {
                        authSvc.SignIn(account);

                        if (userAccountService.IsPasswordExpired(account))
                        {
                            return(RedirectToAction("Index", "ChangePassword"));
                        }

                        if (Url.IsLocalUrl(model.ReturnUrl))
                        {
                            return(Redirect(model.ReturnUrl));
                        }

                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Invalid Code");
                    }
                }
            }

            if (button == "resend")
            {
                ModelState.Clear();
                this.userAccountService.SendTwoFactorAuthenticationCode(this.User.GetUserID());
            }

            return(View("TwoFactorAuthCodeLogin", model));
        }