Generate a random 8-character string for each record

In a product I'm building I'm in a spot where I think I'll need a way to allow users to invite other users to share data.

My thought is if John wants to let Sarah access his records, John will add both Sarah's email address and Sarah's 8-digit code in a form to add her. Meaning, Sarah doesn't need to receive an email to accept, but she would just give John the 8-digit code.

Any time a user record is created, I'll want a code generated.

What's a good way of accomplishing creating this 8-digit string when a user is created or even if the user records already exist?

Other
6 replies