Class: Warden::Passport::Strategy

Inherits:
Strategies::Base
  • Object
show all
Defined in:
lib/warden/passport/strategy.rb

Instance Method Summary collapse

Instance Method Details

#authenticate!Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/warden/passport/strategy.rb', line 8

def authenticate!
  user = User.where(email: params[:user][:email]).first

  encrypted_password = OpenSSL::PKCS5.pbkdf2_hmac_sha1(
    params[:user]['password'],
    user.read_attribute(:salt),
    ENV['PBKDF2_ITERATIONS'].to_i,
    ENV['PBKDF2_LENGTH'].to_i
  ).unpack('H*')[0]

  if encrypted_password == user.read_attribute(:hash)
    success!(user)
  else
    fail!('Could not log in')
  end
end

#valid?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/warden/passport/strategy.rb', line 4

def valid?
  params[:user] && params[:user][:email] && params[:user][:password]
end