public PasswordChangeResult ChangePassword(ChangePasswordRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            var result = new PasswordChangeResult();

            if (String.IsNullOrWhiteSpace(request.Email))
            {
                result.AddError("邮件不能为空");
                return(result);
            }
            if (String.IsNullOrWhiteSpace(request.NewPassword))
            {
                result.AddError("密码不能为空");
                return(result);
            }

            var customer = _userService.GetUserByEmail(request.Email);

            if (customer == null)
            {
                result.AddError("邮件不存在");
                return(result);
            }

            var requestIsValid = false;

            if (request.ValidateRequest)
            {
                //password
                string oldPwd = "";
                customer.Password = Encrypt.GetMd5Code(request.NewPassword);
                bool oldPasswordIsValid = oldPwd == customer.Password;
                if (!oldPasswordIsValid)
                {
                    result.AddError("旧密码错误");
                }

                if (oldPasswordIsValid)
                {
                    requestIsValid = true;
                }
            }
            else
            {
                requestIsValid = true;
            }

            if (requestIsValid)
            {
                customer.Password = Encrypt.GetMd5Code(request.NewPassword);
                _userService.UpdateUser(customer);
            }

            return(result);
        }
Beispiel #2
0
        public PasswordChangeResult ChangePassword(ChangePasswordRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            var result = new PasswordChangeResult();

            if (String.IsNullOrWhiteSpace(request.Email))
            {
                result.AddError("邮件不能为空");
                return(result);
            }
            if (String.IsNullOrWhiteSpace(request.NewPassword))
            {
                result.AddError("密码不能为空");
                return(result);
            }

            var customer = _userService.GetUserByEmail(request.Email);

            if (customer == null)
            {
                result.AddError("邮件不存在");
                return(result);
            }

            var requestIsValid = false;

            if (request.ValidateRequest)
            {
                //password
                string oldPwd = "";
                switch (customer.PasswordFormat)
                {
                case PasswordFormat.Encrypted:
                    oldPwd = Encrypt.GetMd5Code(request.OldPassword);
                    break;

                case PasswordFormat.Hashed:
                    oldPwd = Encrypt.CreatePasswordHash(request.OldPassword, customer.PasswordSalt);
                    break;

                default:
                    oldPwd = request.OldPassword;
                    break;
                }

                bool oldPasswordIsValid = oldPwd == customer.Password;
                if (!oldPasswordIsValid)
                {
                    result.AddError("旧密码错误");
                }

                if (oldPasswordIsValid)
                {
                    requestIsValid = true;
                }
            }
            else
            {
                requestIsValid = true;
            }

            if (requestIsValid)
            {
                switch (request.NewPasswordFormat)
                {
                case PasswordFormat.Clear:
                {
                    customer.Password = request.NewPassword;
                }
                break;

                case PasswordFormat.Encrypted:
                {
                    customer.Password = Encrypt.GetMd5Code(request.NewPassword);
                }
                break;

                case PasswordFormat.Hashed:
                {
                    string saltKey = Encrypt.CreateSaltKey(5);
                    customer.PasswordSalt = saltKey;
                    customer.Password     = Encrypt.CreatePasswordHash(request.NewPassword, saltKey);
                }
                break;

                default:
                    break;
                }
                customer.PasswordFormat = request.NewPasswordFormat;
                _userService.UpdateUser(customer);
            }

            return(result);
        }
Beispiel #3
0
       public PasswordChangeResult ChangePassword(ChangePasswordRequest request)
       {
           if (request == null)
               throw new ArgumentNullException("request");

           var result = new PasswordChangeResult();
           if (String.IsNullOrWhiteSpace(request.Email))
           {
               result.AddError("邮件不能为空");
               return result;
           }
           if (String.IsNullOrWhiteSpace(request.NewPassword))
           {
               result.AddError("密码不能为空");
               return result;
           }

           var customer =_userService.GetUserByEmail(request.Email);
           if (customer == null)
           {
               result.AddError("邮件不存在");
               return result;
           }

           var requestIsValid = false;
           if (request.ValidateRequest)
           {
               //password
               string oldPwd = "";
               switch (customer.PasswordFormat)
               {
                   case PasswordFormat.Encrypted:
                       oldPwd = Encrypt.GetMd5Code(request.OldPassword);
                       break;
                   case PasswordFormat.Hashed:
                       oldPwd = Encrypt.CreatePasswordHash(request.OldPassword, customer.PasswordSalt);
                       break;
                   default:
                       oldPwd = request.OldPassword;
                       break;
               }

               bool oldPasswordIsValid = oldPwd == customer.Password;
               if (!oldPasswordIsValid)
                   result.AddError("旧密码错误");

               if (oldPasswordIsValid)
                   requestIsValid = true;
           }
           else
               requestIsValid = true;

           if (requestIsValid)
           {
               switch (request.NewPasswordFormat)
               {
                   case PasswordFormat.Clear:
                       {
                           customer.Password = request.NewPassword;
                       }
                       break;
                   case PasswordFormat.Encrypted:
                       {
                           customer.Password = Encrypt.GetMd5Code(request.NewPassword);
                       }
                       break;
                   case PasswordFormat.Hashed:
                       {
                           string saltKey = Encrypt.CreateSaltKey(5);
                           customer.PasswordSalt = saltKey;
                           customer.Password = Encrypt.CreatePasswordHash(request.NewPassword, saltKey);
                       }
                       break;
                   default:
                       break;
               }
               customer.PasswordFormat = request.NewPasswordFormat;
               _userService.UpdateUser(customer);
           }

           return result;
       }