T
Thibaut Barrère
Hi,
I'm pretty sure there is a number of options to achieve this, so I'm
asking here. I often need to generate small unique tokens (like for
invitation codes or unimportant authentication token).
In the past I've been using Digest::SHA1.hexdigest(some string) which
gives us something like "d2b7882fa08bb6de8dca62f16298683bfe4f0738".
It's not very user friendly though, and definitely not small.
More recently I've been using ActiveSupport::SecureRandom.base64(6)
which generates "Xst7JGF6" or "zXxWY/Y/", but sometimes it contains
non-url friendly characters like "/".
What do you use ? Is there a specific gem to achieve this in a robust
fashion (= making collisions unlikely, and specify the characters to
be used, like mixture of numbers and characters for instance ?)
cheers and thanks for your input,
Thibaut
I'm pretty sure there is a number of options to achieve this, so I'm
asking here. I often need to generate small unique tokens (like for
invitation codes or unimportant authentication token).
In the past I've been using Digest::SHA1.hexdigest(some string) which
gives us something like "d2b7882fa08bb6de8dca62f16298683bfe4f0738".
It's not very user friendly though, and definitely not small.
More recently I've been using ActiveSupport::SecureRandom.base64(6)
which generates "Xst7JGF6" or "zXxWY/Y/", but sometimes it contains
non-url friendly characters like "/".
What do you use ? Is there a specific gem to achieve this in a robust
fashion (= making collisions unlikely, and specify the characters to
be used, like mixture of numbers and characters for instance ?)
cheers and thanks for your input,
Thibaut