Sha256: 9110690bb16d1fcd144ddbdc80ed73acbdc2725c7962b62f171018be92c7527f

Contents?: true

Size: 1.15 KB

Versions: 10

Compression:

Stored size: 1.15 KB

Contents

# frozen-string-literal: true

module Rodauth
  PasswordGracePeriod = Feature.define(:password_grace_period) 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

10 entries across 10 versions & 1 rubygems

Version Path
rodauth-1.9.0 lib/rodauth/features/password_grace_period.rb
rodauth-1.8.0 lib/rodauth/features/password_grace_period.rb
rodauth-1.7.0 lib/rodauth/features/password_grace_period.rb
rodauth-1.6.0 lib/rodauth/features/password_grace_period.rb
rodauth-1.5.0 lib/rodauth/features/password_grace_period.rb
rodauth-1.4.0 lib/rodauth/features/password_grace_period.rb
rodauth-1.3.0 lib/rodauth/features/password_grace_period.rb
rodauth-1.2.0 lib/rodauth/features/password_grace_period.rb
rodauth-1.1.0 lib/rodauth/features/password_grace_period.rb
rodauth-1.0.0 lib/rodauth/features/password_grace_period.rb