Fixes the username check for api access, and raises the proper type of exception