Sha256: 4dba6cd0b4130e7dd1c2c42c791d9c0b74295c5fcf89bfbd4f8e0ad4f27b1afc

Contents?: true

Size: 1.15 KB

Versions: 8

Compression:

Stored size: 1.15 KB

Contents

# frozen-string-literal: true

module Rodauth
  Feature.define(:password_grace_period, :PasswordGracePeriod) do
    auth_value_method :password_grace_period, 300
    auth_value_method :last_password_entry_session_key, :last_password_entry

    def modifications_require_password?
      return false unless super
      !password_recently_entered?
    end

    def password_match?(_)
      if v = super
        @last_password_entry = set_last_password_entry
      end
      v
    end

    private

    def after_create_account
      super if defined?(super)
      @last_password_entry = Time.now.to_i
    end

    def after_reset_password
      super if defined?(super)
      @last_password_entry = Time.now.to_i
    end

    def update_session
      super
      session[last_password_entry_session_key] = @last_password_entry if defined?(@last_password_entry)
    end

    def password_recently_entered?
      return false unless last_password_entry = session[last_password_entry_session_key]
      last_password_entry + password_grace_period > Time.now.to_i
    end

    def set_last_password_entry
      session[last_password_entry_session_key] = Time.now.to_i
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rodauth-1.17.0 lib/rodauth/features/password_grace_period.rb
rodauth-1.16.0 lib/rodauth/features/password_grace_period.rb
rodauth-1.15.0 lib/rodauth/features/password_grace_period.rb
rodauth-1.14.0 lib/rodauth/features/password_grace_period.rb
rodauth-1.13.0 lib/rodauth/features/password_grace_period.rb
rodauth-1.12.0 lib/rodauth/features/password_grace_period.rb
rodauth-1.11.0 lib/rodauth/features/password_grace_period.rb
rodauth-1.10.0 lib/rodauth/features/password_grace_period.rb