Well, in my humble opinion, it is often needed to create a temporary password for a newly registered user.
This makes it much easier for the user to enter quickly. They are given the temporary password which allows
them to get onto the site quickly. Then, they are forced to change the password. This also allows for the
site to invite others. For instance, one of my sites allows users to invite other users. They are validated by
the ADMIN’s before they are allowed to do anything on the site. But, as I said, there are useful reasons to
create a password. This is one way that a site does it. I think this code came from Stackoverflow and it can
be altered to fit your needs. But, in your code, you need to create the sections separately and then
combine the results.
[php]
// First create new temporary password for the new user. Start with a blank password
$newpassword = “”;
// Define possible characters - any character in this string can be picked for use in the password, so if you want to put vowels back in
// or add special characters such as exclamation marks, this is where you should do it. Note no vowels, so no bad words by accident
$possible = "2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ";
$maxlength = strlen($possible);
// Set up a counter for how many characters are in the password so far
$i = 0;
while ($i < 8) {
$char = substr($possible, mt_rand(0, $maxlength-1), 1);
// Now check for used characters, just do not repeat...
if (!strstr($password, $char)) {
$newpassword .= $char;
$i++;
}
}
[/php]
This code then encrypts the password, marks it as temporary so the user is forced to change it and stores
it all into the database. Now, in your code, if you want different groups for the randomize sections, you
will need to do it in sections. Create the four groups and just concatenate them together. Loosely like
this: $part1=rand(33,47); $part2=rand(58,64); etc then, $pass=$part1.$part2; etc…