public void Handle(CreateUser c)
        {
            var salt = _crypto.GenerateSalt();
            var id   = _crypto.GetMd5Hash(c.Email);

            _repository.Perform(id, user => user.Create(
                                    id,
                                    c.UserName,
                                    _crypto.GetPasswordHash(c.Password, salt),
                                    salt,
                                    c.Email,
                                    c.FacebookId));
        }
        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);
        }
예제 #3
0
        public ActionResult ChangePasswordPost(ChangePasswordModel model)
        {
            var user = _usersService.GetById(UserId);

            if (user.PasswordHash != _cryptoHelper.GetPasswordHash(model.OldPassword, user.PasswordSalt))
            {
                ModelState.AddModelError("OldPassword", "Old password is incorrect.");
            }
            if (ModelState.IsValid)
            {
                var cmd = new ChangePassword
                {
                    Id          = user.Id,
                    NewPassword = model.NewPassword,
                };
                Send(cmd);
                return(Redirect("/"));
            }
            return(View("ChangePassword", model));
        }
예제 #4
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);
        }