This is quite a challenging task for me to do if you could give me some help that would be great.
I am trying to create a password generator after the user fills in the application form and click on the submit button.
It will generate a username and password with 8(numbers or characters),
once the user submits, it will send the username and password to the email specified by the registration and will insert the username and password into a new table in MYSQL but the customerid(primary key) will be the same as the registration details form.
What is the best way to do this? Is it better to use javascript to generate the username and password and then sends it to the user via the email and then insert to MYSQL database.
I know it is easier to insert the username and password to the same table as the registration details, but is it possible to insert into two tables having the same customerid(primary key).
Thanks to all php coder
what's best way to create a password generator?
Moderator: General Moderators
-
gilbertwang
- Forum Commoner
- Posts: 32
- Joined: Sun Jun 30, 2002 11:08 pm
- Location: Calgary
This code will give you the password
I'm sure someone will come up with something better (but in the mean time).
If you have an AUTO_INCREMENT column in your table, when you insert a new row, it's automatically assigned a new number. To get the number just created
$last_id = mysql_insert_id($link_id);
Where $link_id is what's returned from mysql_connect(..).
Code: Select all
function generate_passwd($length = 50)
{
// all the chars we want to use
$all = explode(" ",
"a b c d e f g h j k m n p q r s t w x y z "
."A B C D E F G H J K L M N P Q R S T W X Y Z "
."2 3 4 5 6 7 8 9");
for($i=0;$i<$length;$i++)
{
srand((double)microtime()*1000000);
$randy = rand(0, 61);
if ($allї$randy]!=" "){
$pass .= $allї$randy];
if (strlen($pass)>7){
return $pass;
}}}
}If you have an AUTO_INCREMENT column in your table, when you insert a new row, it's automatically assigned a new number. To get the number just created
$last_id = mysql_insert_id($link_id);
Where $link_id is what's returned from mysql_connect(..).
http://mattford.net , has a great password generator script....
Code: Select all
<?php
function gen_pass($length=7)
{
$alpha = array(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,0,1,2,3,4,5,6,7,8,9);
while($i < $length)
{
$code .= $alphaїrand(0,count($alpha))];
$i++;
}
trim($code);
return $code;
}
?>
For example you could use it like this:
<?php
$password = gen_pass(10);
echo "Your password is $password";
?>