Class: Passpit::Keeper

Inherits:
Object
  • Object
show all
Defined in:
lib/passpit/keeper.rb

Class Method Summary collapse

Class Method Details

.withdraw(name, secret) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/passpit/keeper.rb', line 4

def withdraw(name, secret)
  token = pit[name]

  return 'Password not found.'.colorize(:red) unless token

  begin
    data = JWT.decode(token, secret, true, { algorithm: 'HS256' })
  rescue JWT::VerificationError => error
    return 'Secret phrase is wrong.'.colorize(:red)
  end

  if Clipboard.copy(data[0]['password'])
    return 'The password has been copied to your clipboard.'.colorize(:green)
  else
    return 'Something went wrong.'.colorize(:red)
  end
end