<?

require_once ("include/bittorrent.php");

$id = ( int ) $_GET ["id"];

$md5 = $_GET ["secret"];

if (! $id)
	die ();
dbconn ();

$res = sql_query ( "SELECT passhash, editsecret, status FROM users WHERE id = $id" );
$row = mysql_fetch_array ( $res );

if ($row ["status"] != "pending") {
	location ( "ok.php?type=confirmed" );
	exit ();
}

$sec = hash_pad ( $row ["editsecret"] );

if ($md5 != md5 ( $sec ))
	die ();
sql_query ( "UPDATE users SET status='confirmed', editsecret='' WHERE id=$id AND status='pending'" );

if (! mysql_affected_rows ())
	die ();

logincookie ( $id, $row ["passhash"] );

location ( "ok.php?type=confirm" );

?>