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.28k stars 418 forks source link

Is it generate same hash id for two different numbers? #133

Closed iamsajidjaved closed 5 years ago

iamsajidjaved commented 5 years ago

Hello,

I want to generate a unique random hash for each table record. My requirement is each hash must be unique in the table and will represent a specific record. I don't want to expose my primary keys.

How I generate unique random hashes? I always encode the primary id of my table and as you know the primary key is unique and represent a specific record in a table. So, my input is unique.

My question is, I will get a unique output or not if I pass a unique input?

vinkla commented 5 years ago

I would not recommend to save Hashids in the database.

I would suggest you to take a look at UUID instead: ramsey/uuid

Schyzophrenic commented 5 years ago

@vinkla I was planning to use HashId to obfuscate the primary key as well (in URL for instance). I would not store the hash in the DB but would transform them on the fly when necessary. Are you saying this is the wrong approach? Using uuid would work but it does not generate friendly url...

vinkla commented 5 years ago

...would transform them on the fly when necessary. Are you saying this is the wrong approach?

In your case I would suggest using Hashids.