dc_jt Posted May 16, 2007 Share Posted May 16, 2007 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()); Quote Link to comment https://forums.phpfreaks.com/topic/51622-generate-password-for-each-element-in-array/ Share on other sites More sharing options...
nikkieijpen Posted May 16, 2007 Share Posted May 16, 2007 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()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/51622-generate-password-for-each-element-in-array/#findComment-254308 Share on other sites More sharing options...
dc_jt Posted May 16, 2007 Author Share Posted May 16, 2007 That will do, thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/51622-generate-password-for-each-element-in-array/#findComment-254309 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.