Sha256: a3b8c5267a1ba3146b16ffddc2c3d466d4b52103c5ae79e1fb490e94af846d03

Contents?: true

Size: 1.4 KB

Versions: 17

Compression:

Stored size: 1.4 KB

Contents

# -*- encoding : utf-8 -*-
require_dependency "card/auth/permissions"
require_dependency "card/auth/proxy"
require_dependency "card/auth/setup"

class Card
  # Singleton methods for authentication. Manages current user,
  # "as" user, and password verification.
  module Auth
    extend Permissions
    extend Proxy
    extend Setup
    extend Current

    @as_card = @as_id = @current_id = @current = nil

    class << self
      # authenticate a user by their login name and unencrypted password.
      # @param email [String]
      # @param password [String]
      # @return [+*account card, nil]
      def authenticate email, password
        account = Auth.find_account_by_email email
        case
        when !account                                 then nil
        when !account.active?                         then nil
        when Card.config.no_authentication            then account
        when password_valid?(account, password.strip) then account
        end
      end

      # check whether password is correct for account card
      # @param account [+*account card]
      # @param password [String]
      def password_valid? account, password
        account.password == encrypt(password, account.salt)
      end

      # encrypt password string with the given salt.
      # @return [SHA1 String]
      def encrypt password, salt
        Digest::SHA1.hexdigest "#{salt}--#{password}--"
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
card-1.92.2 lib/card/auth.rb
card-1.92.1 lib/card/auth.rb
card-1.92 lib/card/auth.rb
card-1.91 lib/card/auth.rb
card-1.21.0 lib/card/auth.rb
card-1.20.4 lib/card/auth.rb
card-1.20.3 lib/card/auth.rb
card-1.20.2 lib/card/auth.rb
card-1.20.1 lib/card/auth.rb
card-1.20.0 lib/card/auth.rb
card-1.19.6 lib/card/auth.rb
card-1.19.5 lib/card/auth.rb
card-1.19.4 lib/card/auth.rb
card-1.19.3 lib/card/auth.rb
card-1.19.2 lib/card/auth.rb
card-1.19.1 lib/card/auth.rb
card-1.19.0 lib/card/auth.rb