Jump to content

Generate password for each element in array


dc_jt

Recommended Posts

Hi I have the following code which contains two arrays and a password function.

 

I want to generate a different password for each element in the array, at the moment it is just giving everyone the same one?

 

Here is an example:

 

$name = array("ZEINA MORRIS", "LEANNE DENNIS", "NICKY BROPHY");
$employee_number = array("A393", "A394", "A493");
$password = $oTblLeads->generate_password(4);

for ($i=0; $i < count($name); $i++){

   mysql_query("INSERT INTO cms_users (name, employee_number, pin_code) VALUES ('$name[$i]', '$employee_number[$i]', '$password')")
   or die(mysql_error());

This creates a string of 8 characters long, extracted from a md5 hash of the Employee Number.

 

<?php
$name = array("ZEINA MORRIS", "LEANNE DENNIS", "NICKY BROPHY");
$employee_number = array("A393", "A394", "A493");
$password_length = 8;

for ($i=0; $i < count($name); $i++){
   $pass = md5($employee_number[$i]);
   $password = substr($pass,rand(0,strlen($pass)-$password_length),$password_length);
   mysql_query("INSERT INTO cms_users (name, employee_number, pin_code) VALUES ('$name[$i]', '$employee_number[$i]', '$password')")
   or die(mysql_error());
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.