Commit 20b4cf7b authored by Taylor Otwell's avatar Taylor Otwell

added key generation task.

parent 70dd657e
...@@ -25,6 +25,16 @@ IoC::register('task: bundle', function() ...@@ -25,6 +25,16 @@ IoC::register('task: bundle', function()
return new Tasks\Bundle\Bundler; return new Tasks\Bundle\Bundler;
}); });
/**
* The key task is responsible for generating a secure, random
* key for use by the application when encrypting strings or
* setting the hash values on cookie signatures.
*/
IoC::singleton('task: key', function()
{
return new Tasks\Key;
});
/** /**
* The bundle repository is responsible for communicating with * The bundle repository is responsible for communicating with
* the Laravel bundle sources to get information regarding any * the Laravel bundle sources to get information regarding any
......
<?php namespace Laravel\CLI\Tasks;
use Laravel\Str;
use Laravel\File;
class Key extends Task {
/**
* The path to the application config.
*
* @var string
*/
protected $path;
/**
* Create a new instance of the Key task.
*
* @return void
*/
public function __construct()
{
$this->path = APP_PATH.'config/application'.EXT;
}
/**
* Generate a random key for the application.
*
* @param array $arguments
* @return void
*/
public function generate($arguments = array())
{
// By default the Crypter class uses AES-256 encryption which uses
// a 32 byte input vector, so that is the length of string we will
// generate for the application token unless another length is
// specified through the CLI.
$key = Str::random(array_get($arguments, 0, 32));
$config = str_replace("'key' => '',", "'key' => '{$key}',", File::get($this->path), $count);
File::put($this->path, $config);
if ($count > 0)
{
echo "Configuration updated with secure key!";
}
else
{
echo "An application key already exists!";
}
}
}
\ No newline at end of file
...@@ -91,6 +91,7 @@ Autoloader::$mappings = array( ...@@ -91,6 +91,7 @@ Autoloader::$mappings = array(
'Laravel\\CLI\\Tasks\\Migrate\\Migrator' => SYS_PATH.'cli/tasks/migrate/migrator'.EXT, 'Laravel\\CLI\\Tasks\\Migrate\\Migrator' => SYS_PATH.'cli/tasks/migrate/migrator'.EXT,
'Laravel\\CLI\\Tasks\\Migrate\\Resolver' => SYS_PATH.'cli/tasks/migrate/resolver'.EXT, 'Laravel\\CLI\\Tasks\\Migrate\\Resolver' => SYS_PATH.'cli/tasks/migrate/resolver'.EXT,
'Laravel\\CLI\\Tasks\\Migrate\\Database' => SYS_PATH.'cli/tasks/migrate/database'.EXT, 'Laravel\\CLI\\Tasks\\Migrate\\Database' => SYS_PATH.'cli/tasks/migrate/database'.EXT,
'Laravel\\CLI\\Tasks\\Key' => SYS_PATH.'cli/tasks/key'.EXT,
'Laravel\\Database\\Connection' => SYS_PATH.'database/connection'.EXT, 'Laravel\\Database\\Connection' => SYS_PATH.'database/connection'.EXT,
'Laravel\\Database\\Expression' => SYS_PATH.'database/expression'.EXT, 'Laravel\\Database\\Expression' => SYS_PATH.'database/expression'.EXT,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment