Skip to content

Instantly share code, notes, and snippets.

@thefotolander
Forked from basuke/gen-security.php
Last active August 29, 2015 14:17
Show Gist options
  • Save thefotolander/37f4763a10f3d9a7ad26 to your computer and use it in GitHub Desktop.
Save thefotolander/37f4763a10f3d9a7ad26 to your computer and use it in GitHub Desktop.
<?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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment