Class: NoPassword::Link::Challenge

Inherits:
Base
  • Object
show all
Defined in:
lib/nopassword/link/challenge.rb

Overview

Generates and stores a secure token for link-based authentication. The token is stored in the session and sent via a side channel (email, SMS, etc).

Direct Known Subclasses

Email::Challenge

Constant Summary collapse

TOKEN_SIZE =

16 bytes = 128 bits of entropy

16
DEFAULT_TTL =
10.minutes

Instance Method Summary collapse

Methods inherited from Base

#delete, delete, #initialize, #persisted?, #save!, #save_without_validation, update

Constructor Details

This class inherits a constructor from NoPassword::Link::Base

Instance Method Details

#expires_atObject



22
23
24
# File 'lib/nopassword/link/challenge.rb', line 22

def expires_at
  created_at + ttl.seconds if created_at
end

#saveObject



16
17
18
19
20
# File 'lib/nopassword/link/challenge.rb', line 16

def save
  return false unless valid?
  generate_token!
  super
end