class Net::SSH::Authentication::Methods::Password

  1. lib/net/ssh/authentication/methods/password.rb
Parent: Methods

Implements the "password" SSH authentication method.

Methods

Public Instance

  1. authenticate

Public Instance methods

authenticate (next_service, username, password=nil)

Attempt to authenticate the given user for the given service. If the password parameter is nil, this will never do anything except return false.

[show source]
# File lib/net/ssh/authentication/methods/password.rb, line 14
def authenticate(next_service, username, password=nil)
  return false unless password

  send_message(userauth_request(username, next_service, "password", false, password))
  message = session.next_message

  case message.type
    when USERAUTH_SUCCESS
      debug { "password succeeded" }
      return true
    when USERAUTH_FAILURE
      debug { "password failed" }

      raise Net::SSH::Authentication::DisallowedMethod unless
        message[:authentications].split(/,/).include? 'password'

      return false
    when USERAUTH_PASSWD_CHANGEREQ
      debug { "password change request received, failing" }
      return false
    else
      raise Net::SSH::Exception, "unexpected reply to USERAUTH_REQUEST: #{message.type} (#{message.inspect})"
  end
end