Class: Gloo::Objs::Password
- Inherits:
-
Core::Obj
- Object
- Core::Baseo
- Core::Obj
- Gloo::Objs::Password
- Defined in:
- lib/gloo/objs/security/password.rb
Constant Summary collapse
- KEYWORD =
'password'.freeze
- KEYWORD_SHORT =
'hash'.freeze
- SALT =
'salt'.freeze
- PASSWORD =
'password'.freeze
- HASH =
'hash'.freeze
Constants inherited from Core::Baseo
Core::Baseo::NOT_IMPLEMENTED_ERR
Instance Attribute Summary
Attributes inherited from Core::Obj
Attributes inherited from Core::Baseo
Class Method Summary collapse
-
.messages ⇒ Object
Get a list of message names that this object receives.
-
.short_typename ⇒ Object
The short name of the object type.
-
.typename ⇒ Object
The name of the object type.
Instance Method Summary collapse
-
#add_children_on_create? ⇒ Boolean
Does this object have children to add when an object is created in interactive mode? This does not apply during obj load, etc.
-
#add_default_children ⇒ Object
Add children to this object.
-
#hash ⇒ Object
Get the hashed password value.
-
#msg_check ⇒ Object
Check the password against the hash.
-
#msg_generate ⇒ Object
Generate a random alphanumeric password.
-
#msg_hash ⇒ Object
Hash the password with the salt.
-
#password ⇒ Object
Get the password value.
-
#salt ⇒ Object
Get the password salt.
-
#salt_pwd ⇒ Object
Get the salted password.
-
#update_hash(new_hash) ⇒ Object
Update the hashed password value.
-
#update_password(new_pwd) ⇒ Object
Update the password value.
Methods inherited from Core::Obj
#add_child, can_create?, #can_receive_message?, #child_count, #child_index, #contains_child?, #delete_children, #dispatch, #display_value, #find_add_child, #find_child, help, inherited, #initialize, #is_alias?, #is_function?, #msg_reload, #msg_unload, #multiline_value?, #pn, #remove_child, #render, #root?, #send_message, #set_parent, #set_value, #type_display, #value_display, #value_is_array?, #value_is_blank?, #value_string?
Methods inherited from Core::Baseo
Constructor Details
This class inherits a constructor from Gloo::Core::Obj
Class Method Details
.messages ⇒ Object
Get a list of message names that this object receives.
123 124 125 |
# File 'lib/gloo/objs/security/password.rb', line 123 def self. return super + %w[hash check generate] end |
.short_typename ⇒ Object
The short name of the object type.
33 34 35 |
# File 'lib/gloo/objs/security/password.rb', line 33 def self.short_typename return KEYWORD_SHORT end |
.typename ⇒ Object
The name of the object type.
26 27 28 |
# File 'lib/gloo/objs/security/password.rb', line 26 def self.typename return KEYWORD end |
Instance Method Details
#add_children_on_create? ⇒ Boolean
Does this object have children to add when an object is created in interactive mode? This does not apply during obj load, etc.
100 101 102 |
# File 'lib/gloo/objs/security/password.rb', line 100 def add_children_on_create? return true end |
#add_default_children ⇒ Object
Add children to this object. This is used by containers to add children needed for default configurations.
109 110 111 112 113 114 |
# File 'lib/gloo/objs/security/password.rb', line 109 def add_default_children fac = @engine.factory fac.create_string SALT, '', self fac.create_string PASSWORD, '', self fac.create_string HASH, '', self end |
#hash ⇒ Object
Get the hashed password value. Returns nil if there is none.
76 77 78 79 |
# File 'lib/gloo/objs/security/password.rb', line 76 def hash o = find_child HASH return o&.value end |
#msg_check ⇒ Object
Check the password against the hash. Uses the salt and the hash to check the password.
159 160 161 162 163 |
# File 'lib/gloo/objs/security/password.rb', line 159 def msg_check hashed_pwd = BCrypt::Password.new( hash ) result = ( hashed_pwd == salt_pwd ) @engine.heap.it.set_to result end |
#msg_generate ⇒ Object
Generate a random alphanumeric password. By default the length is 7 characters. Set the length with an optional parameter.
132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/gloo/objs/security/password.rb', line 132 def msg_generate len = 7 if @params&.token_count&.positive? expr = Gloo::Expr::Expression.new( @engine, @params.tokens ) data = expr.evaluate len = data.to_i end s = StringGenerator.alphanumeric( len ) update_password s @engine.heap.it.set_to s return s end |
#msg_hash ⇒ Object
Hash the password with the salt. Uses the salt and the password to create a hash.
150 151 152 153 |
# File 'lib/gloo/objs/security/password.rb', line 150 def msg_hash hashed_pwd = BCrypt::Password.create( salt_pwd ) update_hash hashed_pwd end |
#password ⇒ Object
Get the password value. Returns nil if there is none.
50 51 52 53 |
# File 'lib/gloo/objs/security/password.rb', line 50 def password o = find_child PASSWORD return o&.value end |
#salt ⇒ Object
Get the password salt. Returns nil if there is none.
41 42 43 44 |
# File 'lib/gloo/objs/security/password.rb', line 41 def salt o = find_child SALT return o&.value end |
#salt_pwd ⇒ Object
Get the salted password.
68 69 70 |
# File 'lib/gloo/objs/security/password.rb', line 68 def salt_pwd return "#{salt}#{password}" end |
#update_hash(new_hash) ⇒ Object
Update the hashed password value.
84 85 86 87 88 89 |
# File 'lib/gloo/objs/security/password.rb', line 84 def update_hash( new_hash ) o = find_child HASH return unless o o.set_value new_hash end |
#update_password(new_pwd) ⇒ Object
Update the password value.
58 59 60 61 62 63 |
# File 'lib/gloo/objs/security/password.rb', line 58 def update_password( new_pwd ) o = find_child PASSWORD return unless o o.set_value new_pwd end |