PHP Password Generator Script

Hi Guys,

I have a php password generator script, it worked find to produce the desired password string but once I moved my whole site to a different provider it now wont show the password.

Any help would be great, I can’t see what its not doing.

Below is the actual script. AAAaaahhhhhhhhhhhhhh

<?php if (!empty($str)) { $str=strtolower($str); $cnt=1; $pw1=$str[strlen($str)-$cnt]; $cnt=$cnt+2; $pw2=$str[strlen($str)-$cnt]; if ($pw2==" ") { $cnt++; $pw2=$str[strlen($str)-$cnt]; } $cnt=$cnt+2; $pw3=$str[strlen($str)-$cnt]; if ($pw3==" ") { $cnt++; $pw3=$str[strlen($str)-$cnt]; } $cnt=$cnt+2; $pw4=$str[strlen($str)-$cnt]; if ($pw4==" ") { $cnt++; $pw4=$str[strlen($str)-$cnt]; } $names = explode(" ", $str); $first=$names[1]; $last=$names[0]; $pw5=(ord ($first[0])-98); $pw6=(ord($last[0])-98); $pw=$pw1.$pw3.$pw5.$pw2.$pw4.$pw6; } ?> LCS
Name
Password: <?php if (!empty($str)) { print $pw; } ?>
 

I’d start by echo’ing your variable values as you go, to make sure they are doing what you think.

Also: Define variables first
$pw1=false;
$pw2=false;

Use try/catch to find error
http://php.net/manual/en/language.exceptions.php

Nick, here is a short script that I use to create temporary passwords for new users.
I send it to them inside of an email requiring them to log in and change it to their own.
It is very simple and can be adjusted for whatever you would like. I use letters and numbers
only and so far seems to work well. I also encrypt the password before saving in my DB.

[php]
// 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++;
}
}

// Encrypt the password to be saved into the database for added security
// The user will see the uncrypted version since it is a temporary one. ( Nobody will ever see their new passwords )
$pass = md5(“Some text for salt”, $newpassword);
[/php]
The variable $newpassword is 8 characters long, you can change that and it contains unique characters.
I forget where I got the original sample for this, but, this version works great! Hope it helps…

Sponsor our Newsletter | Privacy Policy | Terms of Service