false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
} catch (PDOException $failure) {
echo "Connection failed: " . $failure->getMessage();
};
/*$servername = "localhost";
$username = "pwtool";
$password = "BaVYtU9YqMyrp4qi";
// Create connection
$conn = mysqli_connect($servername, $username, $password);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully"; */
$displayForm = true;
if(isset($_REQUEST['random'])){
$captchas = new CaptchasDotNet ('demo', 'secret',
'/tmp/captchasnet-random-strings','3600',
'abcdefghkmnopqrstuvwxyz','6',
'240','80','000088');
// Read the form values
//$message = $_REQUEST['message'];
$password = $_REQUEST['password'];
$random_string = $_REQUEST['random'];
$newPassword = str_replace("'", '', trim($_POST['newPassword']));
//$adminPassword = md5(trim($_POST['adminPassword']));
//$dbConnection = pg_connect("host=localhost port=5432 dbname=mypasswd user=mypasswd password=passwdT00l");
//$myLookup = $pdo->query("SELECT id from pwtool where id = 0 and code='".mysqli_real_escape_string($pdo, $adminPassword)."';");
//$myLookup = $pdo->prepare("SELECT id from pwtool.mypasswd where id = 1 and code='$adminPassword';");
//$myLookup->execute();
//$myLookup = $pdo->query("SELECT id from pwtool.mypasswd where id = 0 and code='($adminPassword)';");
//$count = $myLookup->rowCount();
if (!$captchas->validate ($random_string))
{
echo 'The session key (random) does not exist, please go back and reload form.
';
echo 'In case you are the administrator of this page, ';
echo 'please check if random keys are stored correct.
';
echo 'See http://captchas.net/sample/php/ "Problems with save mode"';
}
elseif ($captchas->verify ($password))
{
$displayForm = false;
//$pdo->query($dbConnection, "START TRANSACTION;;");
$myLookup = $pdo->prepare("INSERT INTO pwtool.mypasswd (code, password) VALUES(sha2(CONCAT(rand(),rand(),rand()),256), '$newPassword');");
$myLookup->execute();
$myLookup = $pdo->prepare("SELECT code FROM pwtool.mypasswd WHERE id = LAST_INSERT_ID();");
$myLookup->execute();
$myKey = $myLookup->fetch(PDO::FETCH_OBJ);
//pg_fetch_result($myLookup, 0, 0);
//$pdo->query($dbConnection, "COMMIT");
print '
Password insert succeeded. Here\'s the URL to fetch it:
';
print '
link
';
}
else{
//print '
Nope, not here: '.$adminPassword.'
';
echo 'You entered the wrong captcah. Aren\'t you human?';
}
}
if($displayForm){
?>