Class: Adamantite::Base::Adamantite
- Inherits:
-
Object
- Object
- Adamantite::Base::Adamantite
- Defined in:
- lib/base/adamantite.rb
Instance Attribute Summary collapse
-
#authenticated ⇒ Object
Returns the value of attribute authenticated.
Instance Method Summary collapse
- #authenticate! ⇒ Object
-
#initialize(master_pw) ⇒ Adamantite
constructor
A new instance of Adamantite.
- #update_master_password!(new_master_pw, new_master_pw_confirmation) ⇒ Object
Constructor Details
#initialize(master_pw) ⇒ Adamantite
Returns a new instance of Adamantite.
13 14 15 16 17 |
# File 'lib/base/adamantite.rb', line 13 def initialize(master_pw) @master_pw = master_pw @authenticated = false @master_pw_exists = pw_file_exists?('master') end |
Instance Attribute Details
#authenticated ⇒ Object
Returns the value of attribute authenticated.
11 12 13 |
# File 'lib/base/adamantite.rb', line 11 def authenticated @authenticated end |
Instance Method Details
#authenticate! ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/base/adamantite.rb', line 19 def authenticate! return false unless @master_pw_exists master_pw_info = get_master_pw_info master_pw_hash = master_pw_info['password'] master_pw_salt = master_pw_info['salt'] master_pw_comparator = generate_master_pw_comparator(master_pw_hash) if master_pw_comparator == @master_pw + master_pw_salt @authenticated = true @master_pw_hash = master_pw_hash @master_pw_salt = master_pw_salt @stored_passwords = get_stored_pws true else false end end |
#update_master_password!(new_master_pw, new_master_pw_confirmation) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/base/adamantite.rb', line 37 def update_master_password!(new_master_pw, new_master_pw_confirmation) return false unless new_master_pw == new_master_pw_confirmation && @authenticated new_master_pw_info = generate_master_pw_hash(new_master_pw) new_master_pw_hash = new_master_pw_info[:master_pw_hash] new_master_pw_salt = new_master_pw_info[:salt] @stored_passwords.each do |stored_password| pw_info = get_pw_file(stored_password) pw = decrypt_pw(pw_info['iv'], pw_info['password'], @master_pw, @master_pw_salt) pw_info_for_file = make_pw_info(pw_info['username'], pw, new_master_pw, new_master_pw_salt) write_pw_to_file(stored_password, **pw_info_for_file) end write_pw_to_file('master', password: new_master_pw_hash, salt: new_master_pw_salt) @master_pw_hash = get_master_pw_info @master_pw = new_master_pw @master_pw_salt = new_master_pw_salt true end |