Skip to content

Conversation

@ghost
Copy link

@ghost ghost commented Jan 17, 2013

Changed so that the key be what ever you want when you generate it.

Changed so that the key be what ever you want when you generate it.
@helmut
Copy link
Contributor

helmut commented Jan 17, 2013

To me that seems like a potentially troublesome solution that could error out if the user changes the quotes or spacing between the => in the config file.

How about something like this?

public function fire()
{

    $path = $this->laravel['path'].'/config/app.php';

    $config = $this->files->getRequire($path);

    $contents = $this->files->get($path);

    $contents = str_replace($config['key'], $key = $this->getRandomKey(), $contents, $count);

    if ($count == 0)
    {
        $this->comment('Unable to set application key.');
    }
    else
    {
        $this->files->put($path, $contents);

        $this->info("Application key [$key] set successfully.");
    }
}

@ghost
Copy link
Author

ghost commented Jan 17, 2013

@helmut haha, why didn't I think of that?

@JoostK
Copy link
Contributor

JoostK commented Jan 17, 2013

@helmut That's much better.

I would however ask the user to really override the value if it has already been set. Resetting the key will result in all encrypted/hashed data to become invalid, thus a warning might be appropriate. For people not using Git it may be quite a big problem when they lose their key.

@helmut
Copy link
Contributor

helmut commented Jan 20, 2013

So this is what I end up with..

/**
 * Execute the console command.
 *
 * @return void
 */
public function fire()
{
    $path = $this->laravel['path'].'/config/app.php';

    $config = $this->files->getRequire($path);

    if ($config['key'] !== 'YourSecretKey!!!' and ! $this->confirm('Application key has previously been set. Do you wish to continue? [yes|no]', false))
    {
        $this->info('Application key not set.');
    } 
    else 
    {
        $contents = $this->files->get($path);

        $contents = str_replace($config['key'], $key = $this->getRandomKey(), $contents, $count);

        if ($count == 0)
        {
            $this->info('Unable to set application key.');
        }
        else
        {
            $this->files->put($path, $contents);

            $this->info("Application key [$key] set successfully.");
        }
    }
}

@ghost
Copy link
Author

ghost commented Jan 20, 2013

👍

@taylorotwell
Copy link
Member

Personally, I would like to leave the key generator how it is. Changing it unless you really need to could have adverse affects if you have already encrypted data, as in the data would not be decryptable. If you really need to change it after it has been created, just Google a random password generator.

@mpemberton5
Copy link

Unfortunately, this update broke the key generation when the key field is blank. Might need to 1) check if blank and 2) check if default value, 3) check if existing key exists.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants