<?php

/**
 * @author Capitano ^n3m0^ <capn3m0@gmail.com>
 * @copyright 9-2008
 */

function mosMakePassword($length = 16)
{
    $salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVW XYZ0123456789";
    $makepass = '';
    mt_srand(10000000 * (double)microtime());
    for ($i = 0; $i < $length; $i++) $makepass .= $salt[mt_rand(0, 61)];
    return $makepass;
}

function josHashPassword($password)
{
    // Salt and hash the password
    $salt = mosMakePassword(16);
    $crypt = md5($password . $salt);
    $hash = $crypt . ':' . $salt;

    return $hash;
}

include ("configuration.php");
$sAction = @$_POST["x_action"];
$cfg = new JConfig();

if ($sAction == "")
{
?>
<html>

<form action="" method="post">
<input type="hidden" name="x_action" value="C">
<table border="0">
<tr><td colspan="2" align="center">
Reset Password Admin
</td></tr>
<tr>
<td>Nuova Password</td>
<td><input type="password" name="x_password" size="20"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="submit" value="Imposta">
</td>
</tr>
</table>
</form>
<br>
</html>
<?php
} else
{
    $x_password = @$_POST["x_password"];
	$admin_pwd = josHashPassword($x_password);
    $conn = mysql_connect($cfg->host, $cfg->user, $cfg->password);
    if ($conn == false) die("Errore nella connessione. Verificare i parametri nel file di configurazione");
    mysql_select_db($cfg->db, $conn) or die("Errore nella selezione del database. Verificare i parametri nel file di configurazione");

    $query = "UPDATE " . $cfg->dbprefix . "users SET password='" . $admin_pwd . "' WHERE id='62';";

    $risultato = mysql_query($query,$conn);

    if ($risultato)
    {
?>    	
<table border="0">
<tr><td colspan="2" align="center">
Reset Password Admin
</td></tr>
<tr>
<td>Password scelta</td>
<td><? echo $x_password ?></td>
</tr>
<tr>
<td>Password codificata</td>
<td><? echo $admin_pwd ?></td>
</tr>
<tr>
<td colspan="2" align="center">
Password aggiornata correttamente
</td>
</tr>
</table>
<?
    }
}
?>
