Beispiel #1
0
        public ActionResult ChangePassword(PreferenceChangePasswordModel data)
        {
            SelectCustomerModel customerData = new SelectCustomerModel()
            {
                Email = data.email
            };
            CustomerResultModel customerResult = customerTable.SelectRecord(customerData);

            if (customerResult.CustomerUUID == null)
            {
                return(Json(new { result = "Fail", reason = "Invalid Customer" }));
            }

            bool verifyPassword = Password.VerifyHash(data.oldPassword, customerResult.Hash);

            if (!verifyPassword)
            {
                return(Json(new { result = "Fail", reason = "Invalid Password" }));
            }

            //Generate Password's Salt and Hash
            byte[] salt       = Password.ComputeSaltBytes();
            string hashString = Password.ComputeHash(data.newPassword, salt);
            string saltString = Convert.ToBase64String(salt);

            customerResult.Hash = hashString;
            customerResult.Salt = saltString;

            UpdateCustomerModel customerUpdate = new UpdateCustomerModel()
            {
                CustomerUUID = customerResult.CustomerUUID,
                Email        = customerResult.Email,
                FirstName    = customerResult.FirstName,
                LastName     = customerResult.LastName,
                Hash         = customerResult.Hash,
                Salt         = customerResult.Salt,
                Phone        = customerResult.Phone
            };

            NonQueryResultModel updateResult = customerTable.UpdateRecord(customerUpdate);

            if (updateResult.Success)
            {
                return(Json(new { result = "Success" }));
            }
            else
            {
                return(Json(new { result = "Fail", reason = "Password was not updated" }));
            }
        }