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:
parent
b89537936b
commit
db63df7a8f
1 changed files with 6 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue