function reset_password($username) // set password for username to a random value // return the new password or false on failure { // get a random dictionary word b/w 6 and 13 chars in length $new_password = get_random_word(6, 13); if($new_password==false) return false; // add a number between 0 and 999 to it // to make it a slightly better password srand ((double) microtime() * 1000000); $rand_number = rand(0, 999); $new_password .= $rand_number; // set user's password to this in database or return false if (!($conn = db_connect())) return false; $result = mysql_query( "update user set passwd = password('$new_password') where username = '$username'"); if (!$result) return false; // not changed else return $new_password; // changed successfully }