MyBB Community Forums

Full Version: Is there mass password reset mod?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I just migrated a punbb site to phpbb then to mybb. Well punbb uses a different password setup and all passwords no longer work. What I want to be able to do is do a mass email that will send the new activation code for all members.

Anyone do this already? It would be a nice plugin.
Well I have what I believe is to be a partial code that I pulled from the punbb converter which didn't work entirely but it did email out users a new password.  I ripped this code as best I could and deleted anything I didn't think was needed.  However I am not sure with what's left I know what to do with.  

Can anyone assist?

	$punbbdb->query("SELECT * FROM mybb_users");
	if($punbbdb->num_rows($punbbdb->last_query) > 0)
	{
		while($user = $punbbdb->fetch_array($punbbdb->last_query))
		{

			if(username_exists($user['username']))
			{
				continue;
			}
			if(my_hash())
			{
				$password = $user['password'];
				$salt = generate_salt();
				$loginkey = generate_loginkey();
				$saltedpw = md5(md5($salt).$db->escape_string($password));
			}
			else
			{
				$password = random_str(10);
				$salt = generate_salt();
				$loginkey = generate_loginkey();
				$saltedpw = md5(md5($salt).md5($password));
				my_mail(stripslashes($user['email']), "You got a new password!", "
					We have recently converted from punBB to MyBB, this involved that we couldn't convert your password.
					Your new password is: {$password}.
					You may change the password from the board when you want to. In User CP -> Change Password.
					From the staff at <a href=\"{$mybb->settings['bburl']}\">{$mybb->settings['bbname']}</a>.
				");
			}

			$insert_array = array(
				'username' => $db->escape_string($user['username']),
				'password' => $saltedpw,
				'salt' => $salt,
				'loginkey' => $loginkey,
				'email' => $db->escape_string($user['email']),
			);
			$db->insert_query('mybb_users', $insert_array);
			$uid = $db->insert_id();

		}
		$template->finished = 2;
	}

I would love this as a plugin that would basically reset all passwords and email the user.  This would be a very handy tool for mybb sites that are converted from software with incompatible passwords.

pretty please?
I plan on adding this to the MyBB Merge system for boards where passwords can't be converted.
Have you gotten any code done yet? I am thinking of how to do this as a plugin and thinking about trying to get it on the maintenance page in admincp.

Those are the 2 hooks I guess I would need.

$plugins->run_hooks("admin_maintenance_start");
$plugins->run_hooks("admin_maintenance_rebuild");

I am hoping I can hack together something. Any help you wish to give would be appreciated. If we can hook this onto the maintenance page then you don't need to code it into the converter. An admin can do it on their own time. Normally after a conversion you still need to skin the site and you might have it closed for a few days in the meantime while it's under work. So having this built into admincp seperately has it's advantages.

Let me know what you think about this.
Check out my plugpma.php (private message admin plugin file) for examples on how to add it to nav and take account for admin permissions dynamically.
Well actually I got pretty far in what I did so far. However I am having a stupid problem with looping and foreach. This is what I have so far.

<?php 

//PLUGIN HOOKS

$plugins->add_hook("admin_maintenance_start", "pwreset_menu");

// $plugins->add_hook("admin_maintenance_rebuild", "do_pwreset");


// The information that shows up on the plugin manager
function pwreset_info()
{
	return array(
		"name"			=> "Password Rest",
		"description"	=> "This will add an option to maintenance in admincp to reset all user passwords and then email it to the user.",
		"website"		=> "http://www.mybbcentral.com",
		"author"		=> "Jesse Labrocca",
		"authorsite"	=> "http://www.mybbcentral.com",
		"version"		=> "1.0",
	);
}

// This function runs when the plugin is activated.
function pwreset_activate()
{


}

// This function runs when the plugin is deactivated.
function pwreset_deactivate()
{

}


function pwreset_menu()
{
    global $menu, $mybb, $lang;

  if($mybb->input['action'] == "do_pwreset")
  {
	do_pwreset();
  }

  if($mybb->input['action'] == "rebuild")
 {
	cpheader();
	
	startform("maintenance.php", "" , "do_pwreset");
	starttable();
	tableheader("Reset Passwords");
	makelabelcode("<div align=\"center\">This will reset all but the admin password and then email all members their new password.</div>", '', 2);
	endtable();
	endform($lang->proceed);

  } 

}

function do_pwreset()
{
    global $menu, $mybb, $lang, $db;

	$query = $db->simple_select(TABLE_PREFIX."users", "*", '', array('order_by' => 'uid', 'order_dir' => 'asc', 'limit_start' => $start, 'limit' => $per_page));

	$email = $db->fetch_field($query, 'email');
	$uid = $db->fetch_field($query, 'uid');
    $username = $db->fetch_field($query, 'username');

while($query = $db->fetch_array($query)) {
foreach ($query as $uid){
	
				$password = random_str(10);
				$salt = generate_salt();
				$loginkey = generate_loginkey();
				$saltedpw = md5(md5($salt).md5($password));
				my_mail(stripslashes($email), "You got a new password!", "Dear {$username}
We have reset your password at {$mybb->settings['bbname']}.
Your new password is: {$password}.
You may change the password again if you wish. Go to the forums in User CP -> Change Password.

Thanks you,
{$mybb->settings['bbname']} Staff

<a href=\"{$mybb->settings['bburl']}\">{$mybb->settings['bbname']}</a>.
				");
			

			$insert_array = array(
				'password' => $saltedpw,
				'salt' => $salt,
				'loginkey' => $loginkey,
			);

			$db->update_query(TABLE_PREFIX."users", $insert_array, "username='$username'");

	}

		cpredirect("maintenance.php?".SID."&action=rebuild", "Passwords have been successfully reset and emailed.");

  }

}

?>

The loop doesn't work. It basically does one member and quits. Can you help me fix that loop? I just need it to go to each member by uid I guess.
while($query = $db->fetch_array($query)) {
foreach ($query as $uid){

while ($query =

You just basically overwrote the $query object id with the results to you will never get more than one loop in the while. You need to rename the variable, and make sure your foreach is proper.
I been trying to read tutorials but I am not getting too far. How do I fix those 2 lines? Your help as always is greatly appreciated oh great and mighty tikitiki!
hehe

<?php 

//PLUGIN HOOKS

$plugins->add_hook("admin_maintenance_start", "pwreset_menu");

// $plugins->add_hook("admin_maintenance_rebuild", "do_pwreset");


// The information that shows up on the plugin manager
function pwreset_info()
{
    return array(
        "name"            => "Password Rest",
        "description"    => "This will add an option to maintenance in admincp to reset all user passwords and then email it to the user.",
        "website"        => "http://www.mybbcentral.com",
        "author"        => "Jesse Labrocca",
        "authorsite"    => "http://www.mybbcentral.com",
        "version"        => "1.0",
    );
}

// This function runs when the plugin is activated.
function pwreset_activate()
{


}

// This function runs when the plugin is deactivated.
function pwreset_deactivate()
{

}


function pwreset_menu()
{
    global $menu, $mybb, $lang;

  if($mybb->input['action'] == "do_pwreset")
  {
    do_pwreset();
  }

  if($mybb->input['action'] == "rebuild")
 {
    cpheader();
    
    startform("maintenance.php", "" , "do_pwreset");
    starttable();
    tableheader("Reset Passwords");
    makelabelcode("<div align=\"center\">This will reset all but the admin password and then email all members their new password.</div>", '', 2);
    endtable();
    endform($lang->proceed);

  } 

}

function do_pwreset()
{
    global $menu, $mybb, $lang, $db;

    $query = $db->simple_select(TABLE_PREFIX."users", "*", '', array('order_by' => 'uid', 'order_dir' => 'asc'));

    while($user = $db->fetch_array($query)) 
    {
    
         $password = random_str(10);
         $salt = generate_salt();
         $loginkey = generate_loginkey();
         $saltedpw = md5(md5($salt).md5($password));
          my_mail($user['email'], "You got a new password!", "Dear {$user['username']}
We have reset your password at {$mybb->settings['bbname']}.
Your new password is: {$password}.
You may change the password again if you wish. Go to the forums in User CP -> Change Password.

Thanks you,
{$mybb->settings['bbname']} Staff

<a href=\"{$mybb->settings['bburl']}\">{$mybb->settings['bbname']}</a>.
                ");            

            $update_array = array(
                'password' => $saltedpw,
                'salt' => $salt,
                'loginkey' => $loginkey,
            );

            $db->update_query(TABLE_PREFIX."users", $update_array, "uid='{$user['uid']}'");

    }

        cpredirect("maintenance.php?".SID."&action=rebuild", "Passwords have been successfully reset and emailed.");

}

?>
hehe....same results...

I believe a foreach is needed. I just can't get the syntax right on foreach uid statement.
Pages: 1 2