For example ,
As i registered in daniweb.com , 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);
	mt_srand($seed);
	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

Whereas:

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

.. could give something like:

f0aC8G

Hope it helps!

Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.