i want to creaqte and 8 letter
password which will be diffrent from user to iser
what is the best way to do it
so even if i will generate 8 letters/digits by my self
i want to prevent a case where two users have same password
how do i do that?
thnaks in advance
peleg
generating diffrent passwords
Moderator: General Moderators
a better way to do it useing pickle's suggestion...
this way, you dont need to loop to regenerate.
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);
}
?>
Last edited by qads on Fri Jun 11, 2004 3:36 am, edited 1 time in total.
-
fastfingertips
- Forum Contributor
- Posts: 242
- Joined: Sun Dec 28, 2003 1:40 am
- Contact:
hmm
If you will plan to have more then 1000 users you should let MySQL server to make the comparion and he will return you a bool and if is founded (true) make again otherwise write it in db.
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
?>I'd just use:

Code: Select all
require_once 'Text/Password.php'; //see http://pear.php.net/package/Text_Password
$password = Text_Password::create(8);