Sha256: 87648d5612a2eb454276fd2a91425de078d0aadac289576807b38f4840541b39

Contents?: true

Size: 1.04 KB

Versions: 25

Compression:

Stored size: 1.04 KB

Contents

module Vertica
  module Messages
    class Password < FrontendMessage
      message_id 'p'

      def initialize(password, auth_method = nil, options = {})
        @password = password
        @auth_method = auth_method || Vertica::Messages::Authentication::CLEARTEXT_PASSWORD
        @options = options
      end

      def encoded_password
        case @auth_method
        when Vertica::Messages::Authentication::CLEARTEXT_PASSWORD
          @password
        when Vertica::Messages::Authentication::CRYPT_PASSWORD
          @password.crypt(@options[:salt])
        when Vertica::Messages::Authentication::MD5_PASSWORD
          require 'digest/md5'
          @password = Digest::MD5.hexdigest(@password + @options[:user])
          @password = Digest::MD5.hexdigest(@password + @options[:salt])
          @password = 'md5' + @password
        else
          raise ArgumentError.new("unsupported authentication method: #{@auth_method}")
        end
      end

      def to_bytes
        message_string [encoded_password].pack('Z*')
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
vertica-0.12.0 lib/vertica/messages/frontend_messages/password.rb
vertica-0.11.4 lib/vertica/messages/frontend_messages/password.rb
vertica-0.11.3 lib/vertica/messages/frontend_messages/password.rb
vertica-0.11.2 lib/vertica/messages/frontend_messages/password.rb
vertica-0.11.1 lib/vertica/messages/frontend_messages/password.rb
vertica-0.11.0 lib/vertica/messages/frontend_messages/password.rb
vertica-0.10.5 lib/vertica/messages/frontend_messages/password.rb
vertica-0.10.4 lib/vertica/messages/frontend_messages/password.rb
vertica-0.10.3 lib/vertica/messages/frontend_messages/password.rb
vertica-0.10.2 lib/vertica/messages/frontend_messages/password.rb
vertica-0.10.1 lib/vertica/messages/frontend_messages/password.rb
vertica-0.10.0 lib/vertica/messages/frontend_messages/password.rb
vertica-0.9.6 lib/vertica/messages/frontend_messages/password.rb
vertica-0.9.5 lib/vertica/messages/frontend_messages/password.rb
vertica-0.9.4 lib/vertica/messages/frontend_messages/password.rb
vertica-0.9.3 lib/vertica/messages/frontend_messages/password.rb
vertica-0.9.2 lib/vertica/messages/frontend_messages/password.rb
vertica-0.9.1 lib/vertica/messages/frontend_messages/password.rb
vertica-0.9.0 lib/vertica/messages/frontend_messages/password.rb
vertica-0.9.0.beta9 lib/vertica/messages/frontend_messages/password.rb