Re: [PHP] Problem in a generate password function



Mário Gamito wrote:
Hi,

I have the code of a function to generate a random 10 character long
password following my signature.

To test it i do:

$clearpass = create_pass();
print('Clear: ' . $clearpass);
die();

But the output is only "Clear:"

Why isn't it working ?

Any help would be appreciated.

Warm Regards,
Mário Gamito
--
function create_pass ()
{

$length=10;

$password = "";

$possible = "0123456789abcdefghijklmnopqrstuvxz";

$i = 0;

while ($i < $length) {
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);

I have a very similar routine, but for the previous line, since you can reference a string as an array, I do this:

$char = $possible[mt_rand(0, strlen($possible)-1)];

In this example, it would save ten function calls, if not more.

just a suggestion


if (!strstr($password, $char)) {
$password .= $char;
$i++;
}

}

return $password;

}



--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

.



Relevant Pages

  • Problem in a generate password function
    ... I have the code of a function to generate a random 10 character long ... password following my signature. ... $clearpass = create_pass; ... if (!strstr($password, $char)) { ...
    (php.general)
  • Re: was MLK Jr. "too liberal" iyho?
    ... Jackson & Sharpton protest because blacks have to use the same toilet as whites. ... King was just fine... ... The greatness of a man's character is best judged not by the number of friends he has but by the number of his enemies. ...
    (rec.sport.pro-wrestling)
  • Re: Insane Rush
    ... LG (knows libs have no sense of humor but come on) ... The greatness of a man's character is best judged not by the number of friends he has but by the number of his enemies. ...
    (rec.sport.pro-wrestling)
  • (OT) Oh goodness, the libtards are fired up...
    ... "Shit! ... LG (LOLing) ... The greatness of a man's character is best judged not by the number of friends he has but by the number of his enemies. ...
    (rec.sport.pro-wrestling)
  • Re: If Clinton and Romney win their respective party nominations...
    ... We need Ventura to run, ... LG (shooting) ... The greatness of a man's character is best judged not by the number of friends he has but by the number of his enemies. ...
    (rec.sport.pro-wrestling)