Ask a Question related to PHP Notes, Design and Development.
-
office@rgits.com #1
note 33705 added to function.crypt
there is no passwordgenerator available in php, so i thought i would present mine in here....
Its just a simple function which you could change how you want it........
// function-call
//$digits = amount of chars the password should have (between 4 and 29)
//$c = if true, I,i,L,l will be changed to 1 and O or o will be changed to 0 (Zero) to prevent mistakes by an userinput
//$st = string to "U" = upper, "L" = lower, null=casesensitive
function generate_password($digits,$c,$st)
{
if(!ereg("^([4-9]|((1|2){1}[0-9]{1}))$",$digits)) // 4-29 chars allowed
$digits=4;
for(;;)
{
$pwd=null; $o=null;
// Generates the password ....
for ($x=0;$x<$digits;)
{
$y = rand(1,1000);
if($y>350 && $y<601) $d=chr(rand(48,57));
if($y<351) $d=chr(rand(65,90));
if($y>600) $d=chr(rand(97,122));
if($d!=$o)
{
$o=$d; $pwd.=$d; $x++;
}
}
// if you want that the user will not be confused by O or 0 ("Oh" or "Null")
// or 1 or l ("One" or "L"), set $c=true;
if($c)
{
$pwd=eregi_replace("(l|i)","1",$pwd);
$pwd=eregi_replace("(o)","0",$pwd);
}
// If the PW fits your purpose (e.g. this regexpression) return it, else make a new one
// (You can change this regular-expression how you want ....)
if(ereg("^[a-zA-Z]{1}([a-zA-Z]+[0-9][a-zA-Z]+)+",$pwd))
break;
}
if($st=="L") $pwd=strtolower($pwd);
if($st=="U") $pwd=strtoupper($pwd);
return $pwd;
}
$PASSWORD=generate_password(6,true,null);
have fun ... ;-)
----
Manual Page -- [url]http://www.php.net/manual/en/function.crypt.php[/url]
Edit Note -- [url]http://master.php.net/manage/user-notes.php?action=edit+33705[/url]
Delete Note -- [url]http://master.php.net/manage/user-notes.php?action=delete+33705&report=yes[/url]
Reject Note -- [url]http://master.php.net/manage/user-notes.php?action=reject+33705&report=yes[/url]
office@rgits.com Guest
-
note 33827 added to function.function-exists
This can be used to conditionally define a user function. In this sense, it can act as a sort of inline include_once(). For example, suppose you... -
note 33767 added to function.is-a
>>> USE OF CLASSES, OBJECTS and SESSIONS. <<< If you have an object, or an array that used in many pages, you need to serialize/unserialize it. ... -
note 33727 added to function.is-int
To Logan: There's also a simple non-regexp way to convert a (form) value into an integer if it consists of numbers only - although with a trap... -
note 33714 added to function.register-tick-function
please can anyone help me to discover if this function can be used to make a chat ---- Manual Page --... -
note 33575 added to function.register-shutdown-function
If your script exceeds the maximum execution time, and terminates thusly: Fatal error: Maximum execution time of 20 seconds exceeded in - on line...



Reply With Quote

