Adding method to generate a random key for CAKE_SESSION_STRING when using bake

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4643 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-03-21 20:07:10 +00:00
parent a5aa05da83
commit 77d789c0ac

View file

@ -2088,6 +2088,11 @@ class Bake {
$this->hr();
$this->__defaultHome($projectPath, $appName);
$this->stdout('Welcome page created');
if($this->__generateHash() === true ){
$this->stdout('Random hash key created for CAKE_SESSION_STRING');
} else {
$this->stdout('Unable to generate random hash for CAKE_SESSION_STRING, please change this yourself in ' . CONFIGS . 'core.php');
}
if(chmodr($projectPath.DS.'tmp', 0777) === false) {
$this->stdout('Could not set permissions on '. $projectPath.DS.'tmp'.DS.'*');
$this->stdout('You must manually check that these directories can be wrote to by the server');
@ -2177,6 +2182,22 @@ class Bake {
if (preg_match('%([/\\t\\x20]*define\\(\'CAKE_ADMIN\',[\\t\\x20\'a-z]*\\);)%', $file, $match)) {
$result = str_replace($match[0], 'define(\'CAKE_ADMIN\', \''.$name.'\');', $file);
if(file_put_contents(CONFIGS.'core.php', $result)){
return true;
} else {
return false;
}
} else {
return false;
}
}
function __generateHash(){
$file = file_get_contents(CONFIGS.'core.php');
if (preg_match('/([\\t\\x20]*define\\(\\\'CAKE_SESSION_STRING\\\',[\\t\\x20\'A-z0-9]*\\);)/', $file, $match)) {
uses('Security');
$string = Security::generateAuthKey();
$result = str_replace($match[0], 'define(\'CAKE_SESSION_STRING\', \''.$string.'\');', $file);
if(file_put_contents(CONFIGS.'core.php', $result)){
return true;
} else {