Forum Academy Marketplace Showcase Pricing Features

Create User ID (numbers only) With No Duplicates During Sign Up

Trying to figure out how to assign a user id made up of numbers only for each new user that signs up, I know there is the random string generator that can be converted to numbers but does this feature produce duplicates? If so, any way to work around that? I am building a simple messaging system and would like to keep track of senders/receivers via this “user id” number.

Thanks

Hello @bwvemma
Clean and dirty solution will look like this:
Add new field to User type something like ID with Number as a Field type

During acccount creation do a search for all Users and return results as a count and add to this count 1 and make this number as a ID

3 Likes

Much appreciated @petruch. Quick question, could I use the bubble’s default “unique id” field for something like this?

As far as I know, the random number generator does not guarantee uniqueness, so you would have to test for this in your workflow. So you could have an ‘only when’ search for users with same user_id’s count is zero condition on your workflow step that saves the user. You would of course need the converse step to try again if the search count is > 0.

If you don’t mind people knowing how many users you have when they sign up, you could of course just use current user count + 1 as user_id, as @petrucho suggests, or combine this count with the random number generator somehow to ensure uniqueness.

As far as I know - uniquie ID is hard-coded and non-editable.

I’m not so sure if this is entirely safe. You might have a race condition where 2 or more people sign up at exactly the same time; thus, their IDs will be exactly the same.

Makes sense, so adding the Random Generated String (Numbers only) to the end of current user count as @louisadekoya suggested would be much safer correct?

What i have done in the past is create a data type called “id sequence” with a field called seed. then manually add 1 record into the live data base of 4 numbers.

Now as a user signs up it uses the seed and like what the other guys are saying it then +1 to the seed so it one number higher than for the next.

The difference with what i do though is when i create a user, in the field for id i will compose it like this:

Do search for id sequence’sseed:firstItem now finish the statement and open the composer again and put current date&time:formatted as custom and from memory its L that you want in the custom field and then use users timezone.

This means if your seed is 1234 then you would end up with 1234XX. L (from memory) stands for two of the millisecond digits. Its nearly impossible for 2 people to be right on the same millisecond especially since they would have to do that in the same time zone to end up with the same digits.

This in effect creates a certain amount of random, while keeping an increasing number and also creating the smallest possible time between changes in the time wise to stop any chance of doubles.

Hope that helps.

2 Likes

This topic was automatically closed after 70 days. New replies are no longer allowed.