Friday, 15 March 2013

php - Create a unique and seemingly random 5 character string -



php - Create a unique and seemingly random 5 character string -

i'm trying create short, 5 or 6 character, invitation code generated upon creation of "group" on site. grouping info stored in grouping table. users wishing bring together grouping must have invitation code--it isn't necessary know else.

obviously, need invitation code unique, , hoping generate unique strings without double check, figuring out code has been difficult. i've been reading dozens of questions , answers. i've come with:

when inserting grouping info, such name, grouping table, row given unique, auto-incrementing id, naturally.

1) grab id

2) add together 1234

3) set values next eachother after converting team name base36 base10 eg. "newyorkyankees" base10(3994055806027582482648) [1263399405580602758248264820130221060827])

4) convert base of operations 36

5) insert code database

this guaranteed unique every group, right? 0 chance of collision? because isn't @ random; start unique, , maintain unique, never introducing random data.

i have couple issues though, since grouping names repeatable, how grab row id upon creation/insertion? won't work, it's i'm at:

$query = "select id groups gname = :gname"; ... $uid = $result + '1234'; $hex = md5(":gname now()" . uniqid("$uid", true)); base_convert($hex, 10, 36); intval($str, 36); $query = "insert...";

unique, short, unpredictable without right pieces, aren't available users.

it's described here how lastly inserted auto_increment value.

after having id need utilize symmetric key encryption aes secret key. guaranteed unique (as can transformed original plaintext - called decryption).

you can tune block size desired length (in bits). base64 length multiple of 4 (as 8bit characters encoded in triplets, resulting in 4 character block in base64).

php mysql unique uniqueidentifier

No comments:

Post a Comment