Skip to content

Instantly share code, notes, and snippets.

@basuke
Created April 20, 2011 10:08
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save basuke/930914 to your computer and use it in GitHub Desktop.
Save basuke/930914 to your computer and use it in GitHub Desktop.
Generate CakePHP configuration value for security, Security.salt and Security.cipherSeed.
<?php
$salt = genrandom(40);
$seed = genrandom(29, "0123456789");
echo "\tConfigure::write('Security.salt', '$salt');\n";
echo "\tConfigure::write('Security.cipherSeed', '$seed');\n";
function genrandom($len, $salt = null) {
if (empty($salt)) {
$salt = salt('a', 'z'). salt('A', 'Z'). salt('0', '9');
}
$str = "";
for ($i = 0; $i < $len; $i++) {
$index = rand(0, strlen($salt) - 1);
$str .= $salt[$index];
}
return $str;
}
function salt($from, $end) {
$salt = '';
for ($no = ord($from); $no <= ord($end); $no++) {
$salt .= chr($no);
}
return $salt;
}
@zhmz1326
Copy link

zhmz1326 commented May 8, 2013

Thank u!

@toghou-j
Copy link

awesome !!

@udev
Copy link

udev commented Jul 3, 2013

Thanks :D

@TeddyBear06
Copy link

Thanks :-)

@rgrigga
Copy link

rgrigga commented Jul 25, 2014

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment