lib/net/ldap/password.rb in net-ldap-0.5.1 vs lib/net/ldap/password.rb in net-ldap-0.6.0
- old
+ new
@@ -1,9 +1,10 @@
# -*- ruby encoding: utf-8 -*-
require 'digest/sha1'
require 'digest/md5'
require 'base64'
+require 'securerandom'
class Net::LDAP::Password
class << self
# Generate a password-hash suitable for inclusion in an LDAP attribute.
# Pass a hash type as a symbol (:md5, :sha, :ssha) and a plaintext
@@ -24,10 +25,10 @@
when :md5
attribute_value = '{MD5}' + Base64.encode64(Digest::MD5.digest(str)).chomp!
when :sha
attribute_value = '{SHA}' + Base64.encode64(Digest::SHA1.digest(str)).chomp!
when :ssha
- srand; salt = (rand * 1000).to_i.to_s
+ salt = SecureRandom.random_bytes(16)
attribute_value = '{SSHA}' + Base64.encode64(Digest::SHA1.digest(str + salt) + salt).chomp!
else
raise Net::LDAP::LdapError, "Unsupported password-hash type (#{type})"
end
return attribute_value