in my table, i insert new records of user(new users). I have a int set as field primary key. What i want is to make this id secure. Because this id public to everyone. Any user or people can see this id.
If id i generate is like this:
0000000001
...
0000000023
...
0000000157
...
it is easy for another person to guess it because ids are in a order which is incremented by 1. Instead, i want to store a "public" id in a separate field which is a aplhanumeric representation of this auto_increment primary id.
So in database, table will be like this:
id------------------public_id
---------------------------------
0000000001 -------- W3UB3VNAU3222
0000000002 -------- 7BNXYO28CN2KK
I thought about using hash. But hash is a fixed length of 40 or above. But i want the public id to be fixed 10 characters in length. Should be unique and if possible, I prefer generating it from id
plz tell how to create this ? any builtin functions that helps me to do this?
I read about hash()
function with crc32
:http://www.php.net/manual/en/function.hash.php#104987 It will give 8 char length hash. Will it conflict in future ?
Test:
echo hash('crc32', '0000000001'); // gives 6c13f76e