With ReadableRandom you get readable, short and unique strings.
- Shorter than hexdigest
- More readable than base64
- Totally random
while token.blank? or User.find_by_token(token) self.token = ReadableRandom.get(6) end
With ReadableRandom you get readable, short and unique strings.
while token.blank? or User.find_by_token(token) self.token = ReadableRandom.get(6) end
I suggest using ActiveSupport::SecureRandom instead of OpenSSL. It comes with rails anyways, and if I am not totally wrong it plainly wraps Ruby 1.9’s SecureRandom.
Thanks for the tip, for Rails apps thats true, but it is also meant for non-rails apps, so this was no option. As far as I could see ActiveSupport::SecureRandom uses OpenSsl too (at least on 2.3.2).