public HttpResponseMessage Register(RegisterModel model)
        {
            if (model.Password != model.ConfirmPassword)
            {
                return Error("Passwords must match");
            }

            var policyTest = _encryptionService.TestPasswordPolicy(model.Password);
            if (string.IsNullOrEmpty(policyTest))
            {
                var salt = _encryptionService.GenerateSalt();
                var passwordHash = _encryptionService.CreateHash(model.Password, salt);
                var user = new User
                {
                    ID = Guid.NewGuid(),
                    PasswordHash = passwordHash,
                    Salt = salt,
                    UserName = model.UserName,
                    UserRole = "User"
                };

                _db.Users.Add(user);
                _db.SaveChanges();

                var response = new LoginResponseViewModel
                {
                    IsAuthenticated = true,
                    Username = user.UserName,
                    Role = user.UserRole
                };
                return Success(response);
            }

            return Error(policyTest);
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
                    WebSecurity.Login(model.UserName, model.Password);
                    return RedirectToAction("Index", "Home");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }