コード例 #1
0
        public UserView ValidateUser(string email, string password)
        {
            var user = _users.GetByEmail(email);

            if (user != null && user.PasswordHash == _crypto.GetPasswordHash(password, user.PasswordSalt))
            {
                return(user);
            }
            return(null);
        }
コード例 #2
0
        public ActionResult Reset(string email)
        {
            var user = _usersService.GetByEmail(email);

            if (user == null)
            {
                ModelState.AddModelError("email", "User with this email is not registred.");
            }
            if (ModelState.IsValid)
            {
                var newPass = GenerateNewPassword(7);
                var cmd     = new ResetPassword
                {
                    Id = email
                };
                Send(cmd);
                return(Redirect("/"));
            }
            return(View("Forgot", (object)email));
        }
コード例 #3
0
        public bool Logon(string userName, string password, bool persist)
        {
            var user = _users.GetByEmail(userName);

            if (user != null && _crypto.GetPasswordHash(password, user.PasswordSalt) == user.PasswordHash)
            {
                var authTicket = new FormsAuthenticationTicket(
                    1,
                    user.Email,
                    DateTime.Now,
                    DateTime.Now.AddMinutes(20),
                    persist,
                    null);

                var encryptedTicket = FormsAuthentication.Encrypt(authTicket);

                var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                HttpContext.Current.Response.Cookies.Add(authCookie);

                return(true);
            }

            return(false);
        }