Module: Wpxf::ModuleAuthentication

Included in:
Module
Defined in:
lib/wpxf/core/module_authentication.rb

Overview

Provides functionality for authenticating modules with a WordPress target.

Instance Method Summary collapse

Instance Method Details

#authenticate_with_wordpress(username, password) ⇒ CookieJar, Boolean

Authenticate with WordPress and return the cookie.

Parameters:

  • username (String)

    the username to authenticate with.

  • password (String)

    the password to authenticate with.

Returns:

  • (CookieJar, Boolean)

    the cookie in a CookieJar if successful, otherwise, returns false.



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/wpxf/core/module_authentication.rb', line 35

def authenticate_with_wordpress(username, password)
  emit_info "Authenticating with WordPress using #{username}:#{password}..."
  cookie = (username, password)
  if cookie.nil?
    emit_error 'Failed to authenticate with WordPress'
    return false
  else
    store_credentials username, password
    emit_success 'Authenticated with WordPress', true
    return cookie
  end
end

#initializeObject

Initialize a new instance of Wpxf::ModuleAuthentication.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/wpxf/core/module_authentication.rb', line 7

def initialize
  super
  return unless requires_authentication

  register_options([
    StringOption.new(
      name: 'username',
      desc: 'The WordPress username to authenticate with',
      required: true
    ),
    StringOption.new(
      name: 'password',
      desc: 'The WordPress password to authenticate with',
      required: true
    )
  ])
end

#requires_authenticationBoolean

Returns true if the module requires the user to authenticate.

Returns:

  • (Boolean)

    true if the module requires the user to authenticate.



26
27
28
# File 'lib/wpxf/core/module_authentication.rb', line 26

def requires_authentication
  false
end