Sha256: 854d4bce30d4ce695a5765151b8e3ceaaf646fbe5be4ee29aaf14fe4e42860e0

Contents?: true

Size: 1.34 KB

Versions: 39

Compression:

Stored size: 1.34 KB

Contents

# frozen-string-literal: true

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

    auth_methods :password_recently_entered?

    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

    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 update_session
      super
      set_session_value(last_password_entry_session_key, @last_password_entry) if defined?(@last_password_entry)
    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 set_last_password_entry
      set_session_value(last_password_entry_session_key, Time.now.to_i)
    end

    def require_password_authentication?
      return true if defined?(super) && super
      !password_recently_entered?
    end
  end
end

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
rodauth-2.38.0 lib/rodauth/features/password_grace_period.rb
rodauth-2.37.0 lib/rodauth/features/password_grace_period.rb
rodauth-2.36.0 lib/rodauth/features/password_grace_period.rb
rodauth-2.34.0 lib/rodauth/features/password_grace_period.rb
rodauth-2.33.0 lib/rodauth/features/password_grace_period.rb
rodauth-2.32.0 lib/rodauth/features/password_grace_period.rb
rodauth-2.31.0 lib/rodauth/features/password_grace_period.rb
rodauth-2.30.0 lib/rodauth/features/password_grace_period.rb
rodauth-2.29.0 lib/rodauth/features/password_grace_period.rb
rodauth-2.28.0 lib/rodauth/features/password_grace_period.rb
rodauth-2.27.0 lib/rodauth/features/password_grace_period.rb
rodauth-2.26.1 lib/rodauth/features/password_grace_period.rb
rodauth-2.26.0 lib/rodauth/features/password_grace_period.rb
rodauth-2.25.0 lib/rodauth/features/password_grace_period.rb
rodauth-2.24.0 lib/rodauth/features/password_grace_period.rb
rodauth-2.23.0 lib/rodauth/features/password_grace_period.rb
rodauth-2.22.0 lib/rodauth/features/password_grace_period.rb
rodauth-2.21.0 lib/rodauth/features/password_grace_period.rb
rodauth-2.20.0 lib/rodauth/features/password_grace_period.rb
rodauth-2.19.0 lib/rodauth/features/password_grace_period.rb