Last active
April 1, 2026 20:51
-
-
Save ucan-lab/cba0f7677355e07284fe1e2d5a90cd63 to your computer and use it in GitHub Desktop.
CakePHP4 SECURITY_SALT generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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