Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I set the salt? #21

Open
punchi opened this issue Jan 6, 2015 · 8 comments
Open

How do I set the salt? #21

punchi opened this issue Jan 6, 2015 · 8 comments

Comments

@punchi
Copy link

punchi commented Jan 6, 2015

A random is generated? how/where can I see it? how can I set/change it? the salt it's important!
thanks!

@vinkla
Copy link

vinkla commented Jan 6, 2015

Once you've installed the package, as in the installation guide, you should run the command below to publish the configuration file. Run the following in the root folder of your application:

php artisan config:publish mitch/hashids

This should publish the configuration file app/config/packages/mitch/hashids/config.php. This is where you set the alphabet key or salt as you asked.

@mgleis
Copy link

mgleis commented Jan 6, 2015

How can I use different salts?

@vinkla
Copy link

vinkla commented Jan 6, 2015

@plutus78 How do you mean?

@mgleis
Copy link

mgleis commented Jan 6, 2015

When I use it the laravel style: it always uses the same salt to calculate the hash. But I need differens Generators with different salts because I have different entities I want to secure.

Without your laravel implementation I can use:

$hashids1 = new Hashids\Hashids('this is my salt');
echo $hashids1->encode(1);
$hashids2 = new Hashids\Hashids('this is my second salt');
echo $hashids2->encode(1);

But how can I do it with your implementation?

@vinkla
Copy link

vinkla commented Jan 6, 2015

I don't think its possible out of the box with this package. You could set your own configuration and fetch them with the Config facade.

$hash = new Hashids(Config::get('myconfig.key'));

@punchi
Copy link
Author

punchi commented Jan 7, 2015

the alphabet is not the same as salt, and as @plutus78 says, the salt can change depending the context, @vinkla thanks for a solution =)

hope someday could be like a method to change it, like Hashids::salt('my_salt');

Thanks!

@punchi punchi closed this as completed Jan 7, 2015
@punchi
Copy link
Author

punchi commented Jan 8, 2015

I have a solution!! :D

  • Change \vendor\mitch\hashids\src\Mitch\Hashids\HashidsServiceProvider.php

This

$app['config']['app.key']

To this

$app['config']['hashids::salt']
  • Change \vendor\mitch\hashids\src\config\config.php, add
'salt'     => 'THIS_IS_YOUR_SALT'

And on your config (\app\config\packages\mitch\hashids\config.php) change the values and you'r done!! with this, you can set the salt and you'r not forced to use the crypt one =) however, you can't change it in runtime =(

A variation, you can change the line to $app['config']['app.hashid_salt'] and on config, you can add a different key per environment and you can get it with Config::get('app.hashid_salt'); but you can't change it in runtime too =(

@punchi punchi reopened this Jan 8, 2015
punchi added a commit to punchi/hashids that referenced this issue Jan 8, 2015
punchi added a commit to punchi/hashids that referenced this issue Jan 8, 2015
punchi added a commit to punchi/hashids that referenced this issue Jan 8, 2015
@vinkla
Copy link

vinkla commented Feb 4, 2015

I've created an Laravel 5 supported version of this package https://github.com/vinkla/hashids This version supports multiple salts and connections.

'connections' => [

    'main' => [
        'salt' => 'your-salt-string',
        'length' => 'your-length-integer',
        'alphabet' => 'your-alphabet-string'
    ],

    'alternative' => [
        'salt' => 'your-salt-string',
        'length' => 'your-length-integer',
        'alphabet' => 'your-alphabet-string'
    ],

]

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

No branches or pull requests

3 participants