我只是想了解在生成友好令牌时对特定字符进行编码的理念。这个
背后的思考过程是什么?https://github.com/plataformatec/devise/blob/master/lib/devise.rb#L481
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
在上面的代码片段中,l,I,O,0分别被s,x,y,z替换。那些正在生成的其他角色呢!
示例
SecureRandom.urlsafe_base64(15)
=> "4-6RGWUH1SIsFlXa3C73"
R,G,W等怎么样?
答案 0 :(得分:0)
这背后的唯一原因是删除任何令人困惑的字符。 (很难区分)
像O
一样可能与0
像l
一样可能与I
介绍此内容的特定提交在提交消息中解释了它
https://github.com/plataformatec/devise/commit/6d65c28f1f709722dd86da49241f118813ea7090