mirror of
https://github.com/heartcombo/devise.git
synced 2026-04-28 03:00:29 -04:00
Calculate real characters based on SecureRandom.urlsafe_base64 method
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user