Class: Phpass
- Inherits:
-
Object
- Object
- Phpass
- Defined in:
- lib/phpass.rb,
lib/phpass/md5.rb
Defined Under Namespace
Classes: Md5
Class Method Summary collapse
Instance Method Summary collapse
- #check(pw, hash) ⇒ Object
- #hash(pw, alg = :md5) ⇒ Object
-
#initialize(iter = 8) ⇒ Phpass
constructor
A new instance of Phpass.
Constructor Details
#initialize(iter = 8) ⇒ Phpass
Returns a new instance of Phpass.
8 9 10 11 |
# File 'lib/phpass.rb', line 8 def initialize(iter=8) iter = 8 unless (8..30).include?(iter) @iter = iter end |
Class Method Details
.random_bytes(length) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# 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 |