Return to Snippet

Revision: 50111
at August 11, 2011 04:48 by beneberle


Updated Code
<?php

/* take the following script and modify the connection details and query to suit your needs */

// function to generate salt
function genRandomPassword($length = 32)
{
    $salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    $len = strlen($salt);
    $makepass = '';
    mt_srand(10000000 * (double) microtime());
    for ($i = 0; $i < $length; $i ++) {
        
        $makepass .= $salt[mt_rand(0, $len -1)];
    
    }
    
    return $makepass;
}

// connection
// FILL IN YOUR DATABASE DETAILS HERE
$hostname = "yourhost";
$database = "db_name";
$username = "db_user";
$password = "db_pass";

$site = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR); 
mysql_select_db($database, $site);

// run query
// QUERY TO RETURN USER IDS OF ALL 'registgered' usertypes (gid = 18)

$query = "SELECT * FROM jos_users WHERE gid <= '18'";

$result = mysql_query($query, $site) or die(mysql_error());
$row_result = mysql_fetch_assoc($result);
$num_rows = mysql_num_rows($result);
echo "You're resetting ". $num_rows ." passwords";

do {
    
    
    //generate salt
    $salt = genRandomPassword();

    // update 

    $query_update = "UPDATE jos_users SET password = '" . md5(stripslashes("NEW-PASSWORD").$salt) .':'.$salt . "' WHERE id = " . $row_result['id'];
    $update_result = mysql_query($query_update, $site) or die(mysql_error());
    echo $query_update."<br />";

    
} while ($row_result = mysql_fetch_assoc($result));


?>

Revision: 50110
at August 11, 2011 04:04 by beneberle


Initial Code
<?php

/* take the following script and modify the connection details and query to suit your needs */

// function to generate salt
function genRandomPassword($length = 32)
{
    $salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    $len = strlen($salt);
    $makepass = '';
    mt_srand(10000000 * (double) microtime());
    for ($i = 0; $i < $length; $i ++) {
        
        $makepass .= $salt[mt_rand(0, $len -1)];
    
    }
    
    return $makepass;
}

// connection
// FILL IN YOUR DATABASE DETAILS HERE
$hostname = "yourhost";
$database = "db_name";
$username = "db_user";
$password = "db_pass";

$site = mysql_pconnect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR); 
mysql_select_db($database, $site);

// run query
// QUERY TO RETURN USER IDS OF ALL 'registgered' usertypes (gid = 18)

$query = "SELECT * FROM jos_users WHERE gid <= '18'";

$result = mysql_query($query, $site) or die(mysql_error());
$row_result = mysql_fetch_assoc($result);
$num_rows = mysql_num_rows($result);
echo "You're resetting ". $num_rows ." passwords";

do {

    //$query_update = "UPDATE jos_users SET password = '" . md5(stripslashes("TCT11_SanFran").$salt) .':'.$salt . "' WHERE id = " . $row_result['id'];

    
    
    //generate salt
    $salt = genRandomPassword();

    // update 

    //echo "Run the query!!";
    $query_update = "UPDATE jos_users SET password = '" . md5(stripslashes("NEW-PASSWORD").$salt) .':'.$salt . "' WHERE id = " . $row_result['id'];
    $update_result = mysql_query($query_update, $site) or die(mysql_error());
    echo $query_update."<br />";

    
} while ($row_result = mysql_fetch_assoc($result));


?>

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

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

Initial Title
Batch password reset in Joomla!

Initial Tags
joomla

Initial Language
PHP