Jump to content

Random Password Generation


divyac
 Share

Recommended Posts

I want to generate password randomly and send to mysql database using PHP..i have got the following function for generating password but doesn't know how to incorporate in my registration form and where to call that function and update password field in database..please help me..

	function generatePassword ( $length = 8 ) {	// start with a blank password	$password = “”;	// define possible characters	$possible = “0123456789abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ!@#$%^&*”;	// set up a counter	$i = 0;	// add random characters to $password until $length is reached	while ($i < $length) {	// pick a random character from the possible ones	$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);	// we don’t want this character if it’s already in the password	if (!strstr($password, $char)) {	$password .= $char;	$i++;	}	}	// done!	return $password;	}

where should i call this function generatePassword????

Link to comment
Share on other sites

Where are you inserting the new user into the database?
hey thanks for ur effort...i have written that function in other php file and included it in the current registration file as follows:$pw=generatePassword(8);and inserted $pw in against the password field...its working cool :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...