class Phpass
Public Class Methods
new(iter=8)
click to toggle source
# File lib/phpass.rb, line 8 def initialize(iter=8) iter = 8 unless (8..30).include?(iter) @iter = iter end
random_bytes(length)
click to toggle source
# File lib/phpass.rb, line 23 def self.random_bytes(length) out = '' if File.readable?('/dev/urandom') out = File.read('/dev/urandom', length) end if(out.length < length) random_state = '%s%s' % [Time.now.to_f, $$] out = '' while out.length < length rnd = Digest::MD5.hexdigest(Time.now.to_f.to_s + random_state) out << Digest::MD5.digest(rnd) end out = out[0..length] end out end
Public Instance Methods
check(pw, hash)
click to toggle source
# File lib/phpass.rb, line 18 def check(pw, hash) hasher = Md5.new(@iter) hasher.check(pw, hash) end
hash(pw, alg=:md5)
click to toggle source
# File lib/phpass.rb, line 13 def hash(pw, alg=:md5) hasher = Md5.new(@iter) hasher.hash(pw) end