Hi all,
Just thought I'd share this because why not.
It's the first of hopefully many to come.
Tested on mccodes v2 2.0.5b
Features
It's simple
It provides an easy way to reset someone's password
Easy to install
Tweaks: NonStopCoding / TheMasterGeneral
NonStopCoding Updated Version
<?php
/**
Author: Jacko11208
License: GPL
Filename: staff_pwreset.php
Intented Use: Providing a simple way to reset someone's password via the staff panel
*/
require_once('sglobals.php');
if ($ir['user_level'] != 2)
{
echo 'You cannot access this area.> <a href="staff.php">Go Back</a>';
die($h->endpage());
}
if (!isset($_GET['action']))
$_GET['action'] = '';
switch ($_GET['action'])
{
default:
passreset();
break;
}
function passreset()
{
global $db, $ir, $c, $userid, $h;
if(isset($_POST['submit']))
{
$_POST['user'] =
(isset($_POST['user']) && is_numeric($_POST['user']))
? abs(intval($_POST['user'])) : '';
$_POST['newpassword'] =
(isset($_POST['newpassword']))
? $db->escape(strip_tags(stripslashes($_POST['newpassword']))) : '';
if (empty($_POST['user']) | empty($_POST['newpassword']))
{
echo 'You need to fill in all the fields.
> <a href="staff_pwreset.php?action=passreset">Go Back</a>';
die($h->endpage());
}
else
{
$salt = generate_pass_salt();
$enc_psw = encode_password($_POST['newpassword'], $salt, true);
$e_salt = $db->escape($salt);
$e_encpsw = $db->escape($enc_psw);
$re =
$db->query(
"UPDATE `users` SET `pass_salt` = '{$e_salt}', `userpass` = '{$e_encpsw}'
WHERE `userid` = {$_POST['user']}");
echo 'User has had his password reset
> <a href="staff.php">Go Home</a>';
die($h->endpage());
}
}
else
{
$_GET['XID'] =
(isset($_GET['XID']) && is_numeric($_GET['XID']))
? abs(intval($_GET['XID'])) : 0;
echo "
<h3>Password Reset</h3>
Select the user you wish to reset the password for.
<form method='post'>
User: " . user_dropdown(NULL, 'user', $_GET['XID']). "
New Password: <input type='text' name='newpassword' />
<input type='submit' name='submit' value='Reset Password' />
</form>";
}
$h->endpage();
}
TheMasterGeneral's Version
<?php
//Password Reset Fail - Coming You're Way Thanks To Jacko11208
require_once('sglobals.php');
if (!in_array($ir['user_level'], array(2,7)))
{
$db->query(
"INSERT INTO `fedjail`
VALUES(NULL, {$userid}, 3, 1, 'URL Manipulation')");
$db->query(
"INSERT INTO `jaillogs`
VALUES(NULL, 1, {$userid}, 3,
'URL Manipulation', " . time() . ")");
$db->query(
"UPDATE `users`
SET `fedjail` = 1
WHERE `userid` = {$userid}");
die("Hidden URL. Jail time!");
}
if (!isset($_GET['action']))
{
$_GET['action'] = '';
}
switch ($_GET['action'])
{
case "passreset2":
passreset2();
break;
default:
passreset();
break;
}
function passreset()
{
global $c;
$_GET['XID'] =
(isset($_GET['XID']) && is_numeric($_GET['XID']))
? abs(intval($_GET['XID'])) : 0;
echo "
<h3>Password Reset</h3>
Select the user you wish to reset the password for.
<form action='staff_pwreset.php?action=passreset2' method='post'>
User: " . user_dropdown(NULL, 'user', $_GET['XID'])
. "
New Password: <input type='text' name='newpassword' />
Confirm Password: <input type='text' name='cnewpassword' />
<input type='submit' value='Reset Password' />
</form>
";
}
function passreset2()
{
global $db, $ir, $c, $userid, $h;
$_POST['user'] =
(isset($_POST['user']) && is_numeric($_POST['user']))
? abs(intval($_POST['user'])) : '';
$_POST['newpassword'] =
(isset($_POST['newpassword']))
? $db->escape(strip_tags(stripslashes($_POST['newpassword'])))
: '';
$_POST['cnewpassword'] =
(isset($_POST['cnewpassword']))
? $db->escape(strip_tags(stripslashes($_POST['cnewpassword'])))
: '';
if (empty($_POST['user']) | empty($_POST['newpassword']))
{
echo 'You need to fill in all the fields.
> <a href="staff_pwreset.php?action=passreset">Go Back</a>';
die($h->endpage());
}
if ($_POST['cnewpassword'] != $_POST['newpassword'])
{
echo"Passwords did not match.";
die($h->endpage());
}
$q=$db->query("SELECT `pass_salt`,`userid` FROM `users` WHERE `userid`={$_POST['user']}");
while ($r=$db->fetch_row($q))
{
$new_psw = $db->escape(encode_password($_POST['newpassword'], $r['pass_salt']));
$db->query(
"UPDATE `users`
SET `userpass` = '{$new_psw}'
WHERE `userid` = {$_POST['user']}");
echo "Password changed!
> <a href='preferences.php'>Go Back</a>";
}
}