Sha256: 38e3647032409800e9400d9d9192e1816ac16338eea508d5308a4a8f1aef9d06

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

Contents

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

      def initialize(password, auth_method: Vertica::Protocol::Authentication::CLEARTEXT_PASSWORD, salt: nil, user: nil)
        @password = password
        @auth_method, @salt, @user = auth_method, salt, user
      end

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vertica-1.0.3 lib/vertica/protocol/frontend/password.rb
vertica-1.0.1 lib/vertica/protocol/frontend/password.rb
vertica-1.0.0 lib/vertica/protocol/frontend/password.rb
vertica-1.0.0.rc2 lib/vertica/protocol/frontend/password.rb
vertica-1.0.0.rc1 lib/vertica/protocol/frontend/password.rb