Batch password reset in Joomla!


/ Published in: PHP
Save to your folder(s)

Basic sample courtesy of John Martin @ www.bigspring.co.uk/


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. /* take the following script and modify the connection details and query to suit your needs */
  4.  
  5. // function to generate salt
  6. function genRandomPassword($length = 32)
  7. {
  8. $salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  9. $len = strlen($salt);
  10. $makepass = '';
  11. mt_srand(10000000 * (double) microtime());
  12. for ($i = 0; $i < $length; $i ++) {
  13.  
  14. $makepass .= $salt[mt_rand(0, $len -1)];
  15.  
  16. }
  17.  
  18. return $makepass;
  19. }
  20.  
  21. // connection
  22. // FILL IN YOUR DATABASE DETAILS HERE
  23. $hostname = "yourhost";
  24. $database = "db_name";
  25. $username = "db_user";
  26. $password = "db_pass";
  27.  
  28. $site = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR);
  29. mysql_select_db($database, $site);
  30.  
  31. // run query
  32. // QUERY TO RETURN USER IDS OF ALL 'registgered' usertypes (gid = 18)
  33.  
  34. $query = "SELECT * FROM jos_users WHERE gid <= '18'";
  35.  
  36. $result = mysql_query($query, $site) or die(mysql_error());
  37. $row_result = mysql_fetch_assoc($result);
  38. $num_rows = mysql_num_rows($result);
  39. echo "You're resetting ". $num_rows ." passwords";
  40.  
  41. do {
  42.  
  43.  
  44. //generate salt
  45. $salt = genRandomPassword();
  46.  
  47. // update
  48.  
  49. $query_update = "UPDATE jos_users SET password = '" . md5(stripslashes("NEW-PASSWORD").$salt) .':'.$salt . "' WHERE id = " . $row_result['id'];
  50. $update_result = mysql_query($query_update, $site) or die(mysql_error());
  51. echo $query_update."<br />";
  52.  
  53.  
  54. } while ($row_result = mysql_fetch_assoc($result));
  55.  
  56.  
  57. ?>

URL: http://www.bigspring.co.uk/research-blog/batch-creation-of-joomla-passwords

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.