public UserCreateResult RegisterUser(ApiUserEntity user) { if (user == null) { return(UserCreateResult.Failed); } // check if the username doesnt exist already if (_userRepository.UserNameExists(user.Username)) { return(UserCreateResult.NameAlreadyExists); } // create password for this user. user.Salt = PasswordHash.CreateSalt(user.Username, NumberExtension.GetRandomUniqueCodeWithLength(10)); user.Password = PasswordHash.HashPassword(user.Salt, user.Password); // add the user. _userRepository.Add(user); // save changes. _uow.SaveChanges(); return(UserCreateResult.Success); }