Ejemplo n.º 1
0
        public ChangePasswordResult ChangePassword(ChangePasswordModel model)
        {
            var validationResult = ValidateChangeModel(model);

            if (validationResult != null)
            {
                return(validationResult);
            }

            try
            {
                var currentPasswordOkay = WebSecurity.Login(model.UserName, model.CurrentPassword, false);

                if (!currentPasswordOkay)
                {
                    var badPasswordResult = new ChangePasswordResult
                    {
                        Success = false, Message = "The Current Password supplied is incorrect"
                    };

                    badPasswordResult.AddFailingField(x => x.CurrentPassword);

                    return(badPasswordResult);
                }

                WebSecurityService.UpdatePasswordAndActivate(model.UserName, model.NewPassword);
                return(ChangePasswordResult.Successful);
            }
            catch (Exception e)
            {
                _log.Error("ChangePassword", e);
                return(DatabaseUnreachableResult <ChangePasswordResult>());
            }
        }
Ejemplo n.º 2
0
        public void CreateIdentityUsers()
        {
            try
            {
                foreach (var user in _settings.Users)
                {
                    if (WebSecurity.UserExists(user.UserName))
                    {
                        continue;
                    }

                    _log.Debug($"Adding user: {user} to asp net security.");
                    WebSecurity.CreateUserAndAccount(user.UserName, user.Password, new { FullName = user.Name });

                    foreach (var role in user.Roles)
                    {
                        _log.Debug($"Adding user: {user} to role: {role} in asp net security.");
                        Roles.AddUserToRole(user.Email, role);
                    }

                    _log.Debug($"Applying password to  user: {user} in asp net security.");
                    WebSecurityService.UpdatePasswordAndActivate(user.UserName, user.Password);
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex);
            }
        }
Ejemplo n.º 3
0
        public PasswordResetResult ResetPassword(PasswordResetModel model)
        {
            try
            {
                var validationResult = ValidateResetModel(model);

                if (validationResult != null)
                {
                    return(validationResult);
                }

                WebSecurityService.UpdatePasswordAndActivate(model.UserName, model.Password);

                return(PasswordResetResult.Successful);
            }
            catch (Exception e)
            {
                _log.Error("ResetPassword", e);
                return(DatabaseUnreachableResult <PasswordResetResult>());
            }
        }