Sha256: fb1f90b784d01d701c8efdbdfca743e06210646aaff700010a1eba3ebbf9cab7
Contents?: true
Size: 1.18 KB
Versions: 2
Compression:
Stored size: 1.18 KB
Contents
require "pws" require "rotp" require_relative "otp/version" class PWS module Otp # Gets the TOTP secrect and copies current time based key to the clipboard. # The second parameter is the time in seconds it stays there def get_totp(key, seconds = @options[:seconds]) if real_key = @abbrevs[key] secret = @data[real_key][:password] password = ROTP::TOTP.new(secret).now if seconds && seconds.to_i > 0 original_clipboard_content = Clipboard.paste Clipboard.copy(password) pa %[The password for #{real_key} is now available in your clipboard for #{seconds.to_i} second#{?s if seconds.to_i > 1}], :green begin sleep seconds.to_i rescue Interrupt Clipboard.copy original_clipboard_content raise end Clipboard.copy original_clipboard_content return true else Clipboard.copy(password) pa %[The password for #{real_key} has been copied to your clipboard], :green return true end else pa %[No password found for #{key}!], :red return false end end end end PWS.include(PWS::Otp)
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
pws-otp-0.9.1 | lib/pws/otp.rb |
pws-otp-0.9.0 | lib/pws/otp.rb |