Re: Unique random string

From: Date: Wed, 28 Jun 2000 00:39:45 +0000
Subject: Re: Unique random string
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-3484@lists.php.net to get a copy of this message
I was thinking about this. The main problem is that we do not want to give away the anonymity of our users so not only can we not let people decipher a users system id, but we cannot let anybody figure out that aliases x, y, and z belong to the same user. So even if we hashed their id and appended it you could group together aliases by that quality. I think that even if we did this, or we hashed the entire string, you could not guarantee uniqueness either. Randomness is not as much a problem as guaranteeing uniqueness and making it generally more difficult for somebody to predict the output for future aliases. thanx, Bill p.s. please include my address in any replies. i'm not subscribed to the list. On Tue, 27 Jun 2000, you wrote: > Maybe this may appear a stupid answer but... > > Why don't create a database table and use the auto_increment field as the > first part of the unique id.. > > the second part could be a randomly generated string of x chars... > > You could do this for example.. (supposing MySql) > > $second_part_alias = $rndstr; // a random string of desired characters > lenght > > $query = "insert into first_part_aliases_table > values('','$second_part_alias')"; > // then execute the query > $result = mysql_query($query, $lnk); > $first_part_alias = mysql_insert_id($lnk);// get last insert id > > $unique_alias = $first_part_alias . "-" . $second_part_alias; > // with this you'll be absolutely sure that no duplicates will be generated > > // > Note: > of course you have to estimate how many users will you may have in the next > decade... in order to generate a second_part string not too long > that if concatenated with first part, generates a string longer than 15 > chars.. > > Supposing in the next decade people on the earth will be not more than 20 > Billions > 20,000,000,000 is a 11 chars long string (without commas) you'll create a > string of 3 chars to be concatenated > or > if you want to be sure the alias is 15 chars long you can get the > first_part_alias lenght (that varies if users increment) and calculate the > difference from 15, for the lenght of the string to be concatenated as the > second part... > > > A unique id with this method could be: > > $ID = 34467-dgjGyy // for user number 34467

« previous php.general (#3484) next »