Class: Proxy::Dynflow::OtpManager
- Inherits:
-
Object
- Object
- Proxy::Dynflow::OtpManager
- Defined in:
- lib/smart_proxy_dynflow/otp_manager.rb
Class Method Summary collapse
- .authenticate(hash, expected_user: nil, clear: true) ⇒ Object
- .drop_otp(username, password) ⇒ Object
- .generate_otp(username) ⇒ Object
- .passwords ⇒ Object
- .tokenize(username, password) ⇒ Object
Class Method Details
.authenticate(hash, expected_user: nil, clear: true) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/smart_proxy_dynflow/otp_manager.rb', line 22 def authenticate(hash, expected_user: nil, clear: true) plain = Base64.decode64(hash) username, otp = plain.split(':', 2) if expected_user && expected_user != username return false end password_matches = passwords[username] == otp passwords.delete(username) if clear && password_matches password_matches end |
.drop_otp(username, password) ⇒ Object
14 15 16 |
# File 'lib/smart_proxy_dynflow/otp_manager.rb', line 14 def drop_otp(username, password) passwords.delete(username) if passwords[username] == password end |
.generate_otp(username) ⇒ Object
9 10 11 12 |
# File 'lib/smart_proxy_dynflow/otp_manager.rb', line 9 def generate_otp(username) otp = SecureRandom.hex passwords[username] = otp.to_s end |
.passwords ⇒ Object
18 19 20 |
# File 'lib/smart_proxy_dynflow/otp_manager.rb', line 18 def passwords @password ||= {} end |
.tokenize(username, password) ⇒ Object
34 35 36 |
# File 'lib/smart_proxy_dynflow/otp_manager.rb', line 34 def tokenize(username, password) Base64.strict_encode64("#{username}:#{password}") end |