Skip to Content
Frontlane Studio
All Snippets
PHP WordPress November 14, 2024

Generate and Log Application Passwords for Specific Users

A PHP snippet for Generate and Log Application Passwords for Specific Users.

WordPress PHP

A PHP snippet for Generate and Log Application Passwords for Specific Users.

function generate_app_password_on_login($user_login, $user) {
    // Create a new application password for this user
    $password = WP_Application_Passwords::create_application_password($user->ID);

    // Log the application password creation
    $log = fopen(WP_CONTENT_DIR . '/app-password-log.txt', 'a');
    fwrite($log, "User {$user->user_login} created an app password: {$password}\n");
    fclose($log);
}

add_action('wp_login', 'generate_app_password_on_login', 10, 2);