For example ,
As i registered in , a mail was sent to my email id and after clicking on that link , i could complete my registration .
i want to develop a similar module in php , where the users after signing in , i sent this particular auto-generated link to their email id and confirm their registrations.

Here's a function I wrote long ago which should suit this purpose (I use it for generating random passwords, but it can be used for generating any random code):

function rand_pass ($length = 8, $seeds = null)
	if ($seeds == '')
		$seeds = 'abcdefghijklmnopqrstuvwxyz0123456789';
	$str = '';
	$seeds_count = strlen($seeds);
	list($usec, $sec) = explode(' ', microtime());
	$seed = (float) $sec + ((float) $usec * 100000);
	for ($i = 0; $length > $i; $i++)
		$str .= $seeds{mt_rand(0, $seeds_count - 1)};
	return $str;

The first argument is how long you want it to be, the second is for if you want to provide custom seeds. The "seeds" are possible characters (in one long string).

$pass = rand_pass();

.. would give something such as 02am3y9r


$pass = rand_pass(6, 'abcdefgABCDEFG0123456789');

.. could give something like:


Hope it helps!

Member Avatar


you can use a salted hash to produce the 'code'. This can be based on the username + password + a silly string:

$confirmcode = md5($username + $password + "sc00b13sc00b13d00");
$link = "....?user=$username&conf=$confirmcode";

When the this link is sent to site from email, you just check for the hash and username against values in your DB. You could use an user ID instead of username.