Module: Nova::Starbound::DefaultBehavior::Passwordable

Included in:
Nova::Starbound::DefaultBehavior
Defined in:
lib/nova/starbound/default_behavior/passwordable.rb

Overview

Handles passwords with the default behavior.

API:

  • public

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#password=(value) ⇒ nil, String (writeonly)

The current password. If it’s nil, any password works; if it’s an empty string, no password works; and if it’s a string, only passwords matching that string works.

Returns:

API:

  • public



13
14
15
# File 'lib/nova/starbound/default_behavior/passwordable.rb', line 13

def password=(value)
  @password = value
end

Class Method Details

.included(reciever) ⇒ void

This method returns an undefined value.

When this is included by Nova::Starbound::DefaultBehavior, define the packets nessicary for password management.

API:

  • public



68
69
70
# File 'lib/nova/starbound/default_behavior/passwordable.rb', line 68

def self.included(reciever)
  reciever.handle :packet => :password
end

Instance Method Details

#authenticated?Boolean

Whether or not it was authenticated.

Returns:

API:

  • public



40
41
42
# File 'lib/nova/starbound/default_behavior/passwordable.rb', line 40

def authenticated?
  @authenticated
end

#check_password(pass) ⇒ Boolean

Checks to see if the given password is valid. If it is, it sets authenticated to true. Otherwise, sets it to false.

Parameters:

  • the password to check.

Returns:

API:

  • public



33
34
35
# File 'lib/nova/starbound/default_behavior/passwordable.rb', line 33

def check_password(pass)
  @authenticated = valid_password? pass
end

#valid_password?(pass) ⇒ Boolean

Checks to see if the given password is valid. Returns false if it isn’t, true if it is.

Parameters:

  • the password to check.

Returns:

API:

  • public



20
21
22
23
24
25
26
# File 'lib/nova/starbound/default_behavior/passwordable.rb', line 20

def valid_password?(pass)
  if password.nil? || (pass == password && password != "")
    true
  else
    false
  end
end