vinkla / hashids

A small PHP library to generate YouTube-like ids from numbers. Use it when you don't want to expose your database ids to the user.
https://hashids.org/php
MIT License
5.29k stars 417 forks source link

Is there any max length for the salt? #182

Closed cacharrin closed 2 years ago

cacharrin commented 2 years ago

Doing this:

$length = 5;
$alphabet = "bcdfghjkmnpqrstvwxz23456789";

for ($i = 1; $i < 30; ++$i) {
    $salt = str_repeat('a', $i);
    $encoded = (new Hashids($salt, $length, $alphabet))->encode(1);
    echo "For $i salt: $salt, encoded: $encoded<br/>";
}

Outputs:

For 1 salt: a, encoded: wqxpq
For 2 salt: aa, encoded: r5rz5
For 3 salt: aaa, encoded: 4k76v
For 4 salt: aaaa, encoded: vjw83
For 5 salt: aaaaa, encoded: g78q4
For 6 salt: aaaaaa, encoded: 5m5qm
For 7 salt: aaaaaaa, encoded: kx837
For 8 salt: aaaaaaaa, encoded: 3qrg5
For 9 salt: aaaaaaaaa, encoded: 3pq4g
For 10 salt: aaaaaaaaaa, encoded: rp7gp
For 11 salt: aaaaaaaaaaa, encoded: 2m3xz
For 12 salt: aaaaaaaaaaaa, encoded: 5m5j3
For 13 salt: aaaaaaaaaaaaa, encoded: r374w
For 14 salt: aaaaaaaaaaaaaa, encoded: 3mzq5
For 15 salt: aaaaaaaaaaaaaaa, encoded: 57zq3
For 16 salt: aaaaaaaaaaaaaaaa, encoded: 53zqr
For 17 salt: aaaaaaaaaaaaaaaaa, encoded: 8zrm3
For 18 salt: aaaaaaaaaaaaaaaaaa, encoded: 83rz3
For 19 salt: aaaaaaaaaaaaaaaaaaa, encoded: 83rz3
For 20 salt: aaaaaaaaaaaaaaaaaaaa, encoded: 83rz3
For 21 salt: aaaaaaaaaaaaaaaaaaaaa, encoded: 83rz3
For 22 salt: aaaaaaaaaaaaaaaaaaaaaa, encoded: 83rz3
For 23 salt: aaaaaaaaaaaaaaaaaaaaaaa, encoded: 83rz3
For 24 salt: aaaaaaaaaaaaaaaaaaaaaaaa, encoded: 83rz3
For 25 salt: aaaaaaaaaaaaaaaaaaaaaaaaa, encoded: 83rz3
For 26 salt: aaaaaaaaaaaaaaaaaaaaaaaaaa, encoded: 83rz3
For 27 salt: aaaaaaaaaaaaaaaaaaaaaaaaaaa, encoded: 83rz3
For 28 salt: aaaaaaaaaaaaaaaaaaaaaaaaaaaa, encoded: 83rz3
For 29 salt: aaaaaaaaaaaaaaaaaaaaaaaaaaaaa, encoded: 83rz3

Starting from iteration 17 the encoded value is the same (althought is using a different salt)

Is this a bug?

vinkla commented 2 years ago

Please submit a failing test case in a pull request.

cacharrin commented 2 years ago

I just created the failing test, but when i try to push my branch it throws an error:

remote: Permission to vinkla/hashids.git denied to cacharrin. fatal: unable to access 'https://github.com/vinkla/hashids.git/': The requested URL returned error: 403

EDIT: Just found how to do it, I just created the PR ;)