VOOZH about

URL: https://deepwiki.com/mathsgod/light/5.2.6-password-management

⇱ Password Management | mathsgod/light | DeepWiki


Loading...
Last indexed: 31 January 2026 (cf9511)
Menu

Password Management

Purpose and Scope

This document covers password management functionality in the Light framework, including password expiration policies, password reset flows with JWT-based verification codes, and password change operations.

For basic password authentication and verification during login, see Password Authentication. For token generation after successful authentication, see JWT Token System.


Password Expiration System

The framework supports configurable password expiration policies that force users to update their passwords periodically. This feature is controlled through database configuration settings and enforced at both login time and through dedicated password change endpoints.

Configuration

Password expiration is controlled by two configuration keys stored in the Config model:

Configuration KeyTypeDefaultDescription
password_expirationbooleanfalseEnables/disables password expiration enforcement
password_expiration_durationinteger90Number of days before password expires

Password Age Tracking

Each User record maintains a password_dt timestamp field that records when the password was last changed. This field is updated automatically when:

Expiration Enforcement at Login

During the standard login flow, the system checks password expiration before issuing JWT tokens:


Expiration Check During Login Flow

Sources: src/Controller/AuthController.php446-452

changeExpiredPassword Mutation

The changeExpiredPassword mutation allows users to update expired passwords without authentication:

Method Signature:


Flow Diagram:


changeExpiredPassword Mutation Flow

Key Security Features:

Sources: src/Controller/AuthController.php64-102


Password Reset Flow

The password reset system uses a secure JWT-based verification code mechanism that allows users to reset forgotten passwords via email. The flow involves three mutations working together to provide a secure, rate-limited reset process.

System Architecture


Password Reset System Components

Sources: src/Controller/AuthController.php533-635

Step 1: Initiating Password Reset (forgetPassword)

The forgetPassword mutation initiates the reset process by generating a verification code, sending it via email, and returning a JWT token.

Method Signature:


Process Flow:


forgetPassword Mutation Sequence

JWT Payload Structure:


Email Configuration:

The email sent to the user is configured via the Config model:

Config KeyDefaultDescription
forget_password_email_subject"Password Reset Code"Email subject line
forget_password_email_template"Your password reset code is: {code}"Email body template with {code} placeholder

Security Features:

Sources: src/Controller/AuthController.php597-635

Step 2: Verifying Reset Code (forgetPasswordVerifyCode)

The forgetPasswordVerifyCode mutation validates the user-entered code against the JWT payload with rate limiting.

Method Signature:


Verification Flow:


Code Verification Flow with Rate Limiting

Rate Limiting Mechanism:

Sources: src/Controller/AuthController.php533-552

Step 3: Completing Password Reset (resetPassword)

The resetPassword mutation completes the reset process by validating the code and updating the user's password.

Method Signature:


Reset Flow Diagram:


resetPassword Mutation Flow

Security Features:

Note: The password_dt field is NOT updated during password reset, only during changeExpiredPassword. This is an implementation detail that may need review.

Sources: src/Controller/AuthController.php555-594

Complete Password Reset Sequence


End-to-End Password Reset Flow

Sources: src/Controller/AuthController.php533-635


Password Validation and Policy

The framework enforces password policies through the System::isValidPassword() method, which is called before:

The specific validation rules are implemented in the Light\Type\System class (not shown in provided files, but referenced in the code).

Password Hashing

All passwords are hashed using PHP's password_hash() function with PASSWORD_DEFAULT algorithm:


This currently uses bcrypt, but will automatically upgrade to stronger algorithms as PHP evolves.

Sources: src/Controller/AuthController.php383 src/Controller/AuthController.php588 src/Controller/AuthController.php95


Legacy Password Migration

The framework includes detection for legacy password hashes that used older algorithms (SHA-256/SHA-512 crypt formats).

Legacy Hash Detection

The PasswordVerify private method checks for legacy hash prefixes:


Legacy Password Detection Flow

Legacy Hash Formats:

  • $5 prefix: SHA-256 crypt
  • $6 prefix: SHA-512 crypt

When detected, the system requires manual password reset by an administrator rather than attempting to verify or migrate automatically. This prevents potential security issues with legacy hash algorithms.

Sources: src/Controller/AuthController.php458-465


Integration with Other Authentication Features

Login Integration

Password expiration is checked during the standard login mutation after successful password verification but before JWT token generation src/Controller/AuthController.php446-452 If the password is expired, the login fails with error "password is expired", prompting the user to call changeExpiredPassword.

Initial User Creation

When the system has zero users (first-time setup), the login mutation automatically creates an initial administrator user with:

This allows bootstrapping the system without pre-existing user accounts.

Sources: src/Controller/AuthController.php378-394 src/Controller/AuthController.php446-452


Summary of Mutations

MutationParametersAuthentication RequiredPurpose
changeExpiredPasswordusername, old_password, new_passwordNoUpdate expired password (requires old password)
forgetPasswordusername, emailNoInitiate password reset, returns JWT
forgetPasswordVerifyCodejwt, codeNoVerify reset code (rate-limited)
resetPasswordjwt, password, codeNoComplete password reset with new password

All mutations that modify passwords enforce validation via System.isValidPassword() and use password_hash() with PASSWORD_DEFAULT algorithm.

Sources: src/Controller/AuthController.php64-102 src/Controller/AuthController.php533-635