Exemplo n.º 1
0
        public ChangePasswordResponse ChangePassword(ChangePasswordRequest request)
        {
            var cust = request.Customer;

            var SecuritySettings = (SecuritySection)ConfigurationManager.GetSection("passwordPolicies");

            var PrevPwdsPolicy = SecuritySettings.PasswordPolicies["PreviousPwdsToCheck"];

            int NumberPrevPwdsToCheck = 0;

            if (!int.TryParse(PrevPwdsPolicy.value, out NumberPrevPwdsToCheck))
            {
                throw new Exception(SecurityMethods.PASSWORD_PREVIOUS_TO_CHECK_MISSING);
            }

            var security = new SecurityMethods();
            PasswordCheckResponse PwCheckResponse;

            if (NumberPrevPwdsToCheck > 0)
            {
                //get a list of the number previous passwords in the last six months
                //get the previous passwords
                var PasswordQuery = new Dictionary <String, Object>();
                PasswordQuery.Add("CustomerId", request.Customer.Id);
                var PreviousPasswords = new DL_PreviousPasswords();
                PreviousPasswords.LoadRecords(PasswordQuery);
                //PreviousPasswords = request.Customer.PreviousPasswords.OrderByDescending(e=>e. Where(e => e.ExipirationDate > DateTime.Now.AddMonths(-6)).ToList<PreviousPassword>();
                PwCheckResponse = security.CheckPassword(request.NewPassword,
                                                         PreviousPasswords.PreviousPasswords.OrderByDescending(x => x.CreationDate).Take(NumberPrevPwdsToCheck));
            }

            PwCheckResponse = security.CheckPassword(request.NewPassword, null);

            if (!PwCheckResponse.PasswordOK)
            {
                return(new ChangePasswordResponse {
                    CallResult = 1, Message = PwCheckResponse.Message, MessageType = MessageType.Error
                });
            }

            return(new ChangePasswordResponse {
                CallResult = 0
            });
        }