Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/net/ldap/password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'digest/sha1'
require 'digest/md5'
require 'base64'
require 'securerandom'

class Net::LDAP::Password
class << self
Expand All @@ -26,7 +27,7 @@ def generate(type, str)
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 8
attribute_value = '{SSHA}' + Base64.encode64(Digest::SHA1.digest(str + salt) + salt).chomp!
else
raise Net::LDAP::LdapError, "Unsupported password-hash type (#{type})"
Expand Down