Class: Net::SSH::Authentication::Methods::Password
- Defined in:
- lib/net/ssh/authentication/methods/password.rb
Overview
Implements the “password” SSH authentication method.
Constant Summary
Constants included from Constants
Constants::USERAUTH_BANNER, Constants::USERAUTH_FAILURE, Constants::USERAUTH_METHOD_RANGE, Constants::USERAUTH_PASSWD_CHANGEREQ, Constants::USERAUTH_PK_OK, Constants::USERAUTH_REQUEST, Constants::USERAUTH_SUCCESS
Instance Attribute Summary
Attributes inherited from Abstract
#key_manager, #pubkey_algorithms, #session
Attributes included from Loggable
Instance Method Summary collapse
-
#authenticate(next_service, username, password = nil) ⇒ Object
Attempt to authenticate the given user for the given service.
Methods inherited from Abstract
#initialize, #send_message, #session_id, #userauth_request
Methods included from Loggable
#debug, #error, #fatal, #info, #lwarn
Constructor Details
This class inherits a constructor from Net::SSH::Authentication::Methods::Abstract
Instance Method Details
#authenticate(next_service, username, password = nil) ⇒ Object
Attempt to authenticate the given user for the given service. If the password parameter is nil, this will ask for password
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/net/ssh/authentication/methods/password.rb', line 13 def authenticate(next_service, username, password = nil) clear_prompter! retries = 0 max_retries = get_max_retries return false if !password && max_retries == 0 begin password_to_send = password || ask_password(username) (userauth_request(username, next_service, "password", false, password_to_send)) = session. retries += 1 if .type == USERAUTH_FAILURE debug { "password failed" } raise Net::SSH::Authentication::DisallowedMethod unless [:authentications].split(/,/).include? 'password' password = nil end end until (.type != USERAUTH_FAILURE || retries >= max_retries) case .type when USERAUTH_SUCCESS debug { "password succeeded" } @prompter.success if @prompter return true when USERAUTH_FAILURE return false when USERAUTH_PASSWD_CHANGEREQ debug { "password change request received, failing" } return false else raise Net::SSH::Exception, "unexpected reply to USERAUTH_REQUEST: #{.type} (#{.inspect})" end end |