class SequelAuth::Providers::Crypt
Attributes
method[W]
salt[W]
salt_size[W]
Public Class Methods
defaults()
click to toggle source
# File lib/sequel_auth/providers/crypt.rb, line 42 def defaults { salt: nil, method: :sha512, salt_size: 16, }.freeze end
encrypt(password)
click to toggle source
# File lib/sequel_auth/providers/crypt.rb, line 30 def encrypt(password) if salt password.crypt(salt) else password.crypt(random_salt) end end
matches?(hash, password)
click to toggle source
# File lib/sequel_auth/providers/crypt.rb, line 38 def matches?(hash, password) password.crypt(hash) == hash end
method()
click to toggle source
Salt prefix - prefix for random salt
# File lib/sequel_auth/providers/crypt.rb, line 10 def method @method ||= defaults[:method] end
random_salt()
click to toggle source
# File lib/sequel_auth/providers/crypt.rb, line 24 def random_salt schemes.fetch(method) + (salt_size-schemes.fetch(method).length).times.map { (('a'..'z').to_a + (1..9).to_a + ('A'..'Z').to_a).sample }.join end
salt()
click to toggle source
Salt size
# File lib/sequel_auth/providers/crypt.rb, line 20 def salt @salt ||= defaults[:salt] end
salt_size()
click to toggle source
Salt size - size as number
# File lib/sequel_auth/providers/crypt.rb, line 15 def salt_size @salt_size ||= defaults[:salt_size] end
Private Class Methods
schemes()
click to toggle source
# File lib/sequel_auth/providers/crypt.rb, line 50 def schemes { md5: '$1$', nthash: '$3$$', sha256: '$5$', sha512: '$6$', sha1: '$sha1$' }.freeze end