Sqids return same number if i change last character
vuanh1906 opened this issue · comments
I am using sqids for my application which returns Id with min length of 15 digits:
public static class IdHelper
{
private static readonly SqidsEncoder<int> sqidsEncoder = new SqidsEncoder<int>(new()
{
MinLength = 15,
Alphabet = "k3G7QAe51FCsPW92uEOyq4Bg6Sp8YzVTmnU0liwDdHXLajZrfxNhobJIRcMvKt",
});
public static string Encode(int numericId)
{
return sqidsEncoder.Encode(numericId);
}
public static int Decode(string id)
{
return sqidsEncoder.Decode(id)[0];
}
}
When I try to change a value of one character in the Encoded string, the int value returned is the same. I also tried changing the alphabet but still got the same error.
I use .NET 8, tried testing with the API and it appeared the above error, this error cannot be reproduced in the playground.
Can someone help me clear this ? Did i made any mistake or misunderstanding?
This is due to your max length. You can do a canonicalisation check like in the readme; https://github.com/sqids/sqids-dotnet?tab=readme-ov-file#ensuring-an-id-is-canonical
Thanks Braedon, I understand now