Jump to content

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());
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.