Sha256: 811ca8af324151bcc2bf6579079ba8d05f01245bb60ccad1c7331c4502f9aa5e
Contents?: true
Size: 525 Bytes
Versions: 4
Compression:
Stored size: 525 Bytes
Contents
require "digest/sha2" module Shield module Password def self.encrypt(password, salt = generate_salt) digest(password, salt) + salt end def self.check(password, encrypted) sha512, salt = encrypted.to_s[0..127], encrypted.to_s[128..-1] digest(password, salt) == sha512 end private def self.digest(password, salt) Digest::SHA512.hexdigest("#{ password }#{ salt }") end def self.generate_salt Digest::SHA512.hexdigest(Time.now.to_f.to_s)[0, 64] end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
shield-0.0.3 | lib/shield/password.rb |
shield-0.0.2 | lib/shield/password.rb |
shield-0.0.1 | lib/shield/password.rb |
shield-0.0.0 | lib/shield/password.rb |