Module: DoorMat::Crypto::PasswordHash
- Defined in:
- lib/door_mat/crypto/password_hash.rb
Class Method Summary collapse
- .bcrypt_hash(password, salt = nil) ⇒ Object
- .bcrypt_salt(cost = nil) ⇒ Object
- .pbkdf2_hash(password, salt) ⇒ Object
- .pbkdf2_salt(salt_length = nil, password_length = nil, iterations = nil) ⇒ Object
Class Method Details
.bcrypt_hash(password, salt = nil) ⇒ Object
31 32 33 34 |
# 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) ⇒ Object
25 26 27 28 |
# 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) ⇒ Object
17 18 19 20 21 22 |
# 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) ⇒ Object
8 9 10 11 12 13 14 |
# 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 |