free money is always good, too...
::Random Password Generator::
need a quick, random password?well, here's a script i wrote that generates a random password with a given number of characters, with the choice to select Upper case, Lower case, numberes and / or special characters.
try it out below, and if you like it, keep it. the source code is available to cut/paste below. all i ask is that you somehow link back to this page (or anywhere else on this site). enjoy!
Password will appear here.
===========================================================
source code:
<?php
ob_start(); //start gathering data. prevents buffer overflow
?>
<script type="text/javascript" language="Javascript">
function attachFile(scriptURI)
{
// create new script element, set its relative URL, and load it
script = document.createElement( 'script' );
script.src = scriptURI;
document.getElementsByTagName( 'head' )[0].appendChild( script );
}
</script>
<blockquote style="border:solid 2px red; padding: 5px 5px 5px 5px; background-color: #ffffff; color: #000000;" id="passwordBlock"><i>Password will appear here.</i><br/> </blockquote>
<!--display form for options. 'onkeyup' erases any non-numeric characters.-->
<form name="passwordGenerator" id="passwordGenerator" method="post">
<table>
<tr><td><input type="text" name="length" id="length" value="8" size="2" maxlength="2" onkeyup="this.value=this.value.replace(/[^0-9]/g,'')"/></td><td>number of characters (8+ for stronger passwords, 99 limit)</td></tr>
<tr><td align="right"><input type="checkbox" name="useUpper" id="useUpper" checked/></td><td>Use upper case characters (ABCD...)</td></tr>
<tr><td align="right"><input type="checkbox" name="useLower" id="useLower" checked/></td><td>Use lower case characters (abcd...)</td></tr>
<tr><td align="right"><input type="checkbox" name="useNumbers" id="useNumbers" checked/></td><td>Use numbers (0123...)</td></tr>
<tr><td align="right"><input type="checkbox" name="useSpecialChars" id="useSpecialChars" checked/></td><td>Use special characters ([email protected]#$...)</td></tr>
<tr><td align="middle" colspan="2"><input type="button" name="generatePassword" id="generatePassword" value="generate password" onclick="javascript:attachFile('randomPassword-javascript.inc.php?length=' + document.getElementById('length').value + '&useUpper=' + document.getElementById('useUpper').checked + '&useLower=' + document.getElementById('useLower').checked + '&useNumbers=' + document.getElementById('useNumbers').checked + '&useSpecialChars=' + document.getElementById('useSpecialChars').checked )" />
</table>
</form>
<?php
ob_end_flush(); //done gathering, let it all out!
?>
1
<?php
ob_start();
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT\n"); //fix for IE caching first generated password
header( 'Content-Type: text/javascript' );
function fGenerateRandomPassword($length,$useUpperCase,$useLowerCase,$useNumbers,$useSpecialChars)
{
//define strings for each category
$upperCase = "ABCDEFGHIJKLNOPQRSTUVWXYZ";
$lowerCase = strtolower($upperCase);
$numbers = "0123456789";
$specialChars = "[email protected]#$%^&*()?";
//adds characters from category if selected
$toUse = "";
$countToUse = 0;
if($useUpperCase == "true") { $toUse .= $upperCase; $countToUse++; }
if($useLowerCase == "true") { $toUse .= $lowerCase; $countToUse++; }
if($useNumbers == "true") { $toUse .= $numbers; $countToUse++; }
if($useSpecialChars == "true") { $toUse .= $specialChars; $countToUse++; }
if($length < $countToUse) //if number entered is less that the count of selected character sets.
{
return "<i><b>\"number of characters\"</b> can not be less than selection of characters to use.</i><br/>";
break;
}
//no errors, generate the password
$password = "";
for ($i = 0; $i < $length; $i++)
{
$password .= $toUse[(rand() % strlen($toUse))];
}
//define the array to return
$passwordArray[0] = $password;
$passwordArray[1] = $upperCase;
$passwordArray[2] = $lowerCase;
$passwordArray[3] = $numbers;
$passwordArray[4] = $specialChars;
//check that the password contains at LEAST 1 character from each selected category
$hasUpper = strpbrk($passwordArray[0],$passwordArray[1]);
$hasLower = strpbrk($passwordArray[0],$passwordArray[2]);
$hasNumber = strpbrk($passwordArray[0],$passwordArray[3]);
$hasSpecChar = strpbrk($passwordArray[0],$passwordArray[4]);
if(($useUpperCase == "true" && $hasUpper == "") || ($useLowerCase == "true" && $hasLower == "") || ($useNumbers == "true" && $hasNumber == "") || ($useSpecialChars == "true" && $hasSpecChar == ""))
{
return "FALSE";
}
//it contains everything it needs... return the password
else
{
$password = "Your password is:<br/><b>".$passwordArray[0]."</b>";
return $password;
}
}
do // get the password to display
{
$password = fGenerateRandomPassword($_GET['length'],$_GET['useUpper'],$_GET['useLower'],$_GET['useNumbers'],$_GET['useSpecialChars']);
}
while($password=="FALSE") // until it's not returned as 'FALSE'
?>
document.getElementById('passwordBlock').innerHTML = '<?php echo $password; ?>';
<?php
ob_end_flush();
?>
1