HEX
Server: nginx/1.18.0
System: Linux vps-9dcdb12e 5.15.0-176-generic #186-Ubuntu SMP Fri Mar 13 11:01:42 UTC 2026 x86_64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.24
Disabled: exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source
Upload Files
File: /var/www/rowerowawaga.pl/wp-content/plugins/integromat-connector/class/class-api-token.php
<?php

namespace Integromat;

defined( 'ABSPATH' ) || die( 'No direct access allowed' );

class Api_Token {

	const API_TOKEN_IDENTIFIER = 'iwc_api_key';

	const API_TOKEN_LENGTH = 32;

	/**
	 * Return existing token
	 *
	 * @return string
	 */
	public static function get() {
		return get_site_option( self::API_TOKEN_IDENTIFIER );
	}


	/**
	 * Initiate a token if it doesn't exist
	 *
	 * @throws \Exception
	 */
	public static function initiate() {
		if ( self::get() == '' ) {
			// Use WordPress secure password generation for better entropy
			$secure_token = wp_generate_password( self::API_TOKEN_LENGTH, true, true );
			update_site_option( self::API_TOKEN_IDENTIFIER, $secure_token );
		}
	}


	/**
	 * @param string $token
	 * @return bool
	 */
	public static function is_valid( $token ) {
		// Use hash_equals to prevent timing attacks
		$stored_token = get_site_option( self::API_TOKEN_IDENTIFIER );
		return hash_equals( $stored_token, $token );
	}

	/**
	 * Regenerate API token
	 *
	 * @return string New token
	 * @throws \Exception
	 */
	public static function regenerate() {
		$new_token = wp_generate_password( self::API_TOKEN_LENGTH, true, true );
		update_site_option( self::API_TOKEN_IDENTIFIER, $new_token );
		return $new_token;
	}

}