Class: UnixCrypt::MD5
Class Method Summary collapse
- .byte_indexes ⇒ Object
- .digest ⇒ Object
- .hash(password, salt, ignored = nil) ⇒ Object
- .identifier ⇒ Object
- .length ⇒ Object
Methods inherited from Base
Class Method Details
.byte_indexes ⇒ Object
45 46 47 |
# File 'lib/unix_crypt.rb', line 45 def self.byte_indexes [[0, 6, 12], [1, 7, 13], [2, 8, 14], [3, 9, 15], [4, 10, 5], [nil, nil, 11]] end |
.digest ⇒ Object
41 |
# File 'lib/unix_crypt.rb', line 41 def self.digest; Digest::MD5; end |
.hash(password, salt, ignored = nil) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/unix_crypt.rb', line 49 def self.hash(password, salt, ignored = nil) salt = salt[0..7] b = digest.digest("#{password}#{salt}#{password}") a_string = "#{password}$1$#{salt}#{b * (password.length/length)}#{b[0...password.length % length]}" password_length = password.length while password_length > 0 a_string += (password_length & 1 != 0) ? "\x0" : password[0].chr password_length >>= 1 end input = digest.digest(a_string) 1000.times do |index| c_string = ((index & 1 != 0) ? password : input) c_string += salt unless index % 3 == 0 c_string += password unless index % 7 == 0 c_string += ((index & 1 != 0) ? input : password) input = digest.digest(c_string) end base64encode(input) end |
.identifier ⇒ Object
43 |
# File 'lib/unix_crypt.rb', line 43 def self.identifier; 1; end |
.length ⇒ Object
42 |
# File 'lib/unix_crypt.rb', line 42 def self.length; 16; end |