module DoorMat::Crypto::PasswordHash
Public Class Methods
bcrypt_hash(password, salt=nil)
click to toggle source
# File lib/door_mat/crypto/password_hash.rb, line 31 def bcrypt_hash(password, salt=nil) salt ||= bcrypt_salt BCrypt::Engine.hash_secret(password.to_str, salt.to_str) end
bcrypt_salt(cost=nil)
click to toggle source
# File lib/door_mat/crypto/password_hash.rb, line 25 def bcrypt_salt(cost=nil) cost ||= DoorMat.configuration.crypto_bcrypt_cost BCrypt::Engine.generate_salt(Integer(cost)) end
pbkdf2_hash(password, salt)
click to toggle source
# File lib/door_mat/crypto/password_hash.rb, line 17 def pbkdf2_hash(password, salt) length, iterations, salt = salt.to_str.split('--').map { |s| Base64.strict_decode64(s) } Base64.strict_encode64( OpenSSL::PKCS5.pbkdf2_hmac_sha1(password.to_str, salt, Integer(iterations), Integer(length)) ) end
pbkdf2_salt(salt_length=nil, password_length=nil, iterations=nil)
click to toggle source
# File lib/door_mat/crypto/password_hash.rb, line 8 def pbkdf2_salt(salt_length=nil, password_length=nil, iterations=nil) salt_length ||= DoorMat.configuration.crypto_pbkdf2_salt_length password_length ||= DoorMat.configuration.crypto_pbkdf2_password_length iterations ||= DoorMat.configuration.crypto_pbkdf2_iterations [password_length, iterations, OpenSSL::Random.random_bytes(salt_length)].map { |s| Base64.strict_encode64(s.to_s)}.join('--') end
Private Instance Methods
bcrypt_hash(password, salt=nil)
click to toggle source
# File lib/door_mat/crypto/password_hash.rb, line 31 def bcrypt_hash(password, salt=nil) salt ||= bcrypt_salt BCrypt::Engine.hash_secret(password.to_str, salt.to_str) end
bcrypt_salt(cost=nil)
click to toggle source
# File lib/door_mat/crypto/password_hash.rb, line 25 def bcrypt_salt(cost=nil) cost ||= DoorMat.configuration.crypto_bcrypt_cost BCrypt::Engine.generate_salt(Integer(cost)) end
pbkdf2_hash(password, salt)
click to toggle source
# File lib/door_mat/crypto/password_hash.rb, line 17 def pbkdf2_hash(password, salt) length, iterations, salt = salt.to_str.split('--').map { |s| Base64.strict_decode64(s) } Base64.strict_encode64( OpenSSL::PKCS5.pbkdf2_hmac_sha1(password.to_str, salt, Integer(iterations), Integer(length)) ) end
pbkdf2_salt(salt_length=nil, password_length=nil, iterations=nil)
click to toggle source
# File lib/door_mat/crypto/password_hash.rb, line 8 def pbkdf2_salt(salt_length=nil, password_length=nil, iterations=nil) salt_length ||= DoorMat.configuration.crypto_pbkdf2_salt_length password_length ||= DoorMat.configuration.crypto_pbkdf2_password_length iterations ||= DoorMat.configuration.crypto_pbkdf2_iterations [password_length, iterations, OpenSSL::Random.random_bytes(salt_length)].map { |s| Base64.strict_encode64(s.to_s)}.join('--') end