Skip to content

Validate salt length? #31

@hoffi

Description

@hoffi

The salt appears to have a maximum length after which it has no longer impacts the generated hash.

Here some examples:

Hashids.new('a' * 41).encode(1)
=> "pn" 
Hashids.new('a' * 42).encode(1)
=> "nd" 
Hashids.new('a' * 43).encode(1)
=> "yQ" 
Hashids.new('a' * 44).encode(1)
=> "yQ" 
Hashids.new('a' * 45).encode(1)
=> "yQ" 

If i change the alphabet it also affects this maximum length:

Hashids.new('a' * 22, 0, 'abcdefghijkmnopqrstuvwxyz023456789').encode(1)
=> "b0" 
Hashids.new('a' * 23, 0, 'abcdefghijkmnopqrstuvwxyz023456789').encode(1)
=> "bd" 
Hashids.new('a' * 24, 0, 'abcdefghijkmnopqrstuvwxyz023456789').encode(1)
=> "bd" 
Hashids.new('a' * 25, 0, 'abcdefghijkmnopqrstuvwxyz023456789').encode(1)
=> "bd" 

Looks like something around (alphabet.length * 0.7).floor is the maximum length?

Should this be validated and raise a SaltError when the salt is too long?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions