Included Modules
Attributes
| [W] | messenger | The messenger to use when communicating. |
Public Class methods
Create a new Password authenticator. It will use the given buffers factory to create new buffer instances.
[ show source ]
# File lib/net/ssh/userauth/methods/password.rb, line 34
34: def initialize( buffers )
35: @buffers = buffers
36: end
Public Instance methods
Attempt to authenticate the given user for the given service. The data hash must specify a :password value, otherwise this will always return false.
[ show source ]
# File lib/net/ssh/userauth/methods/password.rb, line 41
41: def authenticate( next_service, username, data={} )
42: return false unless data[:password]
43:
44: msg = @buffers.writer
45: msg.write_byte USERAUTH_REQUEST
46: msg.write_string username
47: msg.write_string next_service
48: msg.write_string "password"
49: msg.write_bool false
50: msg.write_string data[:password]
51: @messenger.send_message msg
52:
53: message = @messenger.wait_for_message
54:
55: case message.message_type
56: when USERAUTH_SUCCESS
57: return true
58: when USERAUTH_FAILURE, USERAUTH_PASSWD_CHANGEREQ
59: return false
60: else
61: raise Net::SSH::Exception,
62: "unexpected reply to USERAUTH_REQUEST: #{message.inspect}"
63: end
64: end