Page 1 of 1

How can i create many logins with one submition of form. ???

Posted: Sun Aug 05, 2007 2:58 am
by djdon11
Hi Friends ..

once again i needs your help ..

well i have a registration form which makes a user for my site .. now i have to give user a option of many login password with the same username .. for this i have a drop down(select) box on my form in which i have numbers from 1 to 12 that means user can select a number and when he submits the form there should be randomly genrated no. of passwords he selected (the no.) suppose if he selects 5 in drop down than there should b randomly genrated 5 passwords for his username that means he will than have 5 logins with same username but the passwords will different for each login.....

how can i do this in the database ... can i insert more than 1 records for a one submit means on one click can i insert more than 1 records in the database ... ??

if anybody have any idea or may want some more details than please do reply...

thanks

Posted: Sun Aug 05, 2007 5:16 am
by kaszu
You can save password in separate table and set password column as unique (primary key).
When in inserting each password into database, just check if insert was successful and if it wasn't generate another key and try once more.
Not sure if that's the best way to do it, but that's what i could think of.

How can i create many logins with one submition of form. ???

Posted: Sun Aug 05, 2007 5:19 am
by djdon11
but how can i insert all the records on 1 click .... means 5 passwords inserted on just 1 click .. how can ... ???

Posted: Sun Aug 05, 2007 6:06 am
by kaszu
If you are using mysql:

Code: Select all

$number_of_passwords = 5;
$user_id = 123;

for($i = 0; $i < $number_of_passwords; $i++)
{
    $password = substr(md5(time() . rand(0, 10000)), 0, 6);      //Generating random 6 character password
    $password_sql = mysql_real_escape_string($password);    //Escaping

    $sql = 'INSERT INTO password_table (unique_password, user_id) VALUES ("' . $password_sql. '", "' . $user_id . '")';
    mysql_query($sql);
    
    if (mysql_affected_rows() == 0)
    {
        $i--;
    }else{
        echo 'Generated password: ' . $password;
    }
}
Haven't tested, but should work. It needs to insert each password separately, because we need to regenerate password if it already exists in the table.

Hi again

Posted: Mon Aug 06, 2007 12:56 pm
by djdon11
hi now i have some different problem here

i hope i will get the help as before .....

Code: Select all

for($j=0;$j<4;$j++){	
		$rndval = date("s") ;
$rndval .= rand().rand().rand();
$rndval;
$rndval  = substr($rndval,0,9);

$password="";
for ($i=0;$i<9;$i++)
{
	$password .= chr(substr($rndval, $i,1)+105);
}

}
this code gives me the 5 diffrent passwords but now i need to store all this 5 passwords in a variable ....

how can i do that can anybody help me ...


thanks