lib/active_ldap/user_password.rb in activeldap-1.0.2 vs lib/active_ldap/user_password.rb in activeldap-1.0.9
- old
+ new
@@ -1,8 +1,8 @@
require 'English'
-require 'md5'
-require 'sha1'
+require 'digest/md5'
+require 'digest/sha1'
module ActiveLdap
module UserPassword
module_function
def valid?(password, hashed_password)
@@ -41,44 +41,44 @@
crypted_password[0, 2]
end
end
def md5(password)
- "{MD5}#{[MD5.md5(password).digest].pack('m').chomp}"
+ "{MD5}#{[Digest::MD5.digest(password)].pack('m').chomp}"
end
def smd5(password, salt=nil)
if salt and salt.size != 4
raise ArgumentError, _("salt size must be == 4: %s") % salt.inspect
end
salt ||= Salt.generate(4)
- md5_hash_with_salt = "#{MD5.md5(password + salt).digest}#{salt}"
+ md5_hash_with_salt = "#{Digest::MD5.digest(password + salt)}#{salt}"
"{SMD5}#{[md5_hash_with_salt].pack('m').chomp}"
end
def extract_salt_for_smd5(smd5ed_password)
Base64.decode64(smd5ed_password)[-4, 4]
end
def sha(password)
- "{SHA}#{[SHA1.sha1(password).digest].pack('m').chomp}"
+ "{SHA}#{[Digest::SHA1.digest(password)].pack('m').chomp}"
end
def ssha(password, salt=nil)
if salt and salt.size != 4
raise ArgumentError, _("salt size must be == 4: %s") % salt.inspect
end
salt ||= Salt.generate(4)
- sha1_hash_with_salt = "#{SHA1.sha1(password + salt).digest}#{salt}"
+ sha1_hash_with_salt = "#{Digest::SHA1.digest(password + salt)}#{salt}"
"{SSHA}#{[sha1_hash_with_salt].pack('m').chomp}"
end
def extract_salt_for_ssha(sshaed_password)
extract_salt_for_smd5(sshaed_password)
end
module Salt
- CHARS = ['.', '/', '0'..'9', 'A'..'Z', 'a'..'z'].collect do |x|
+ CHARS = ['.', '/'] + ['0'..'9', 'A'..'Z', 'a'..'z'].collect do |x|
x.to_a
end.flatten
module_function
def generate(length)