File: password.rb

package info (click to toggle)
libnet-ssh2-ruby 2.0.15-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 812 kB
  • ctags: 1,400
  • sloc: ruby: 8,839; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 1,277 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
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
require 'net/ssh/errors'
require 'net/ssh/authentication/methods/abstract'

module Net
  module SSH
    module Authentication
      module Methods

        # Implements the "password" SSH authentication method.
        class Password < Abstract
          # Attempt to authenticate the given user for the given service. If
          # the password parameter is nil, this will never do anything except
          # return false.
          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" }
                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
        end

      end
    end
  end
end