1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Calculate real characters based on SecureRandom.urlsafe_base64 method

This commit is contained in:
Angel M de Miguel 2015-05-21 14:41:34 +02:00
parent b89537936b
commit db63df7a8f

View file

@ -465,9 +465,12 @@ module Devise
end
# Generate a friendly string randomly to be used as token.
# By default, length is 15 characters.
def self.friendly_token(length = 15)
SecureRandom.urlsafe_base64(length).tr('lIO0', 'sxyz')
# By default, length is 20 characters.
def self.friendly_token(length = 20)
# To calculate real characters, we must perform this operation.
# See SecureRandom.urlsafe_base64
rlength = (length * 3) / 4
SecureRandom.urlsafe_base64(rlength).tr('lIO0', 'sxyz')
end
# constant-time comparison algorithm to prevent timing attacks