Bulk User Account Password Encryption

3 posts by 2 authors in: Forums > CMS Builder
Last Post: May 29, 2013   (RSS)

By Steve99 - May 29, 2013

Hello,

I'm looking for a way to bulk encrypt user passwords for use with CMSB/Membership Plugin. I have a few hundred rows of users to do this for and really don't want to do this manually...

Thanks in advance.

- Steve

By gregThomas - May 29, 2013

Hi Steve,

Are you using the default accounts section to store users passwords? If so you can encrypt them easily by checking the encrypt passwords checkbox in the general settings area of CMS Builder. 

If you're storing the passwords in a different section you could use this script:

<?php

  // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('C:/wamp/www/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

  $records = mysql_select('section_name_here');


  echo 'Script Started!<br>';
  foreach($records as $record){
    echo 'Password encryped for record '.$record['num'].'<br>';
    if($record['password']){
      $passwordHash = getPasswordDigest($record['password']);
      mysql_update('blog', $record['num'], null, array('password' => $passwordHash));
    }
  }

  echo 'SCRIPT RAN SUCCESSFULLY, DO NOT RUN AGAIN!';
?>

So to get the script to run you just need to change section_name_here for the name of the section that contains your website members. 

Make sure you do a full back up of the database before running the script!

Also, if you run the script a second time it will encrypt the already encrypted passwords.

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com