Skip to content

Instantly share code, notes, and snippets.

@ucan-lab
Last active April 1, 2026 20:51
Show Gist options
  • Select an option

  • Save ucan-lab/cba0f7677355e07284fe1e2d5a90cd63 to your computer and use it in GitHub Desktop.

Select an option

Save ucan-lab/cba0f7677355e07284fe1e2d5a90cd63 to your computer and use it in GitHub Desktop.
CakePHP4 SECURITY_SALT generator
<?php declare(strict_types=1);
final class CakePHPSecuritySaltGenerator
{
/**
* @return string
*/
public function generate(): string
{
return uniqid(bin2hex(random_bytes(32)));
}
/**
* @return void
*/
public function generateAndReplace(): void
{
$salt = $this->generate();
$env = file_get_contents('config/.env');
file_put_contents('config/.env', str_replace('__SALT__', $salt, $env));
}
}
$generator = new CakePHPSecuritySaltGenerator();
$generator->generateAndReplace();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment