The problem I am trying to solve is to validate if a username is already used before allowing an admin user to create a new user with that username.
Currently I am doing an ajax request to check if the username is taken. This can cause a lag that detracts from the user experience - especially as they are encouraged to create more than 30 usernames at once during the onboarding process.
I wonder if there is a hashing algorithm that allows the backend to construct a string that the frontend can use to check if a new username is in the set.
on the backend
usernames_set = jim, carl, fred my_hash = generate_hash(usernames_set) // returns e.g., 23223edw3234fcvdvc # now pass this hash to the frontend.
on the frontend
checkValueInHash('jim') // returns true checkValueInHash('nigel') // returns false
I appreciate I can simply pass the set of usernames to the frontend, but this would become infeasible as the number of items in the set becomes thousands. Also, there is security implications of proving a list of valid usernames.
Note I indent to solve the consistency problem (what happens when new users are created after the hash is sent to the frontend?) by using websockets to push a new string when new users are created.
Also note I appreciate I reduce this problem by sending username checks in bulk, but I would like to understand what other options are available too.