Exemplo n.º 1
0
        public RegisterUserResponse RegisterUser(RegisterCustomerRequest request)
        {
            var ct = request.NewCustomer;

            //convert Customer to DLCustomer
            ADL_Customer CustomerToSave;

            if (MockCustomer == null)
            {
                CustomerToSave = GetMappingObject().MapCustomertoDLCustomer(ct);
            }
            else
            {
                CustomerToSave = MockCustomer;
            }

            ISecurityMethods security;

            if (MockSecurity == null)
            {
                security = new SecurityMethods();
            }
            else
            {
                security = MockSecurity;
            }

            //Add additional fields
            byte[] Salt = security.GenerateNewSalt();
            CustomerToSave.Salt = Salt;
            CustomerToSave.PasswordNeedsChanging = false;
            CustomerToSave.UserName     = request.UserName;
            CustomerToSave.PasswordHash = security.GetPasswordHash(Salt, request.Password);

            try
            {
                CustomerToSave.Save();
            }
            catch (Exception e)
            {
                return(new RegisterUserResponse {
                    CallResult = 1, Message = REGISTER_CUSTOMER_SAVE_FAILED + "\n" + e.Message, MessageType = MessageType.Error
                });
            }

            return(new RegisterUserResponse {
                CallResult = 0
            });
        }
Exemplo n.º 2
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
            });
        }