hi there...
i want to genrate a random string like a3nd29sas3 can any one help me.
thanks.
how to genrate random string
Moderator: General Moderators
-
method_man
- Forum Contributor
- Posts: 257
- Joined: Sat Mar 19, 2005 1:38 am
ive searched this site and found some different solutions.
1.
2.
and 3.
all 3 of these can be found on this url: viewtopic.php?t=22563&highlight=random+string
1.
Code: Select all
<?php
$string = password();//a function which returns 5 letters/numbers/mixed value
$check = mysql_num_rows(mysql_query("select password from table where password = '$string'"));
if($check > 0)
{
$rand = rand(10, 32);
$md = md5($string.time());
$string .= $md{$rand}.($check + 1);
}
?>Code: Select all
<?php
function makeRand ($minlength, $maxlength, $useupper, $usespecial, $usenumbers)
{ //Random string generator
$key="";
$charset = "abcdefghijklmnopqrstuvwxyz";
if ($useupper) $charset .= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if ($usenumbers) $charset .= "0123456789";
if ($usespecial) $charset .= "~@#$%^*()_+-={}|][";
if ($minlength > $maxlength) $length = mt_rand ($maxlength, $minlength);
else $length = mt_rand ($minlength, $maxlength);
for ($i=0; $i<$length; $i++) $key .= $charset[(mt_rand(0,(strlen($charset)-1)))];
return $key;
}
do
{
$tempPass="";
$tempPass=$this->utils->makeRand(15,15,1,0,1);
} while(in_array($tempPass,$arrPass));
//$arrPass is a array of present passwords
?>Code: Select all
require_once 'Text/Password.php'; //see http://pear.php.net/package/Text_Password
$password = Text_Password::create(8);-
method_man
- Forum Contributor
- Posts: 257
- Joined: Sat Mar 19, 2005 1:38 am
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
anjanesh wrote this little random text generator too...
(Conveniently named simpleRandomTextGenerater
)
viewtopic.php?t=34337
(Conveniently named simpleRandomTextGenerater
viewtopic.php?t=34337