Auto populate custom userid identifier field on user creation

If You’re using office365 or something, There is
https://github.com/discourse/discourse-plugin-office365-auth
Which will authenticate the users with their existing office365 credentials.

If it is something else, You’re looking into a plugin territory. to get values from the database, Maybe try using:
https://github.com/discourse/discourse-data-explorer