Class: Vertica::Protocol::Password

Inherits:
FrontendMessage show all
Defined in:
lib/vertica/protocol/frontend/password.rb

Instance Method Summary collapse

Methods inherited from FrontendMessage

#to_bytes

Methods inherited from Message

message_id

Constructor Details

#initialize(password, auth_method: Vertica::Protocol::Authentication::CLEARTEXT_PASSWORD, salt: nil, user: nil) ⇒ Password

Returns a new instance of Password.



6
7
8
9
# File 'lib/vertica/protocol/frontend/password.rb', line 6

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

Instance Method Details

#encoded_passwordObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/vertica/protocol/frontend/password.rb', line 11

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

#message_bodyObject



27
28
29
# File 'lib/vertica/protocol/frontend/password.rb', line 27

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