Single file processing
This commit is contained in:
parent
d9522084f9
commit
e91a936677
164
add.php
164
add.php
|
|
@ -1,164 +0,0 @@
|
|||
<?php
|
||||
|
||||
require 'CaptchasDotNet.php';
|
||||
|
||||
$captchas = new CaptchasDotNet ('demo', 'secret',
|
||||
'/tmp/captchasnet-random-strings','3600',
|
||||
'abcdefghkmnopqrstuvwxyz','6',
|
||||
'240','80','000088');
|
||||
?>
|
||||
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>Password Fetch tool</title>
|
||||
<style type="text/css">
|
||||
body{
|
||||
padding: 32px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body style="width: 500px; margin: auto; font-family: Verdana, Geneva, sans-serif; font-size: 14px;">
|
||||
<br /><br />
|
||||
<div align="center" style="width: 500px">
|
||||
<div style="border: 1px solid #000000; text-align: center; background: #486b92; font-size: 20px; color: #ffffff;">
|
||||
<strong>One Time Password Retrieval Tool</strong>
|
||||
</div>
|
||||
<div style="border: 1px solid #000000; text-align: left; padding: 8px;">
|
||||
<?php
|
||||
try {
|
||||
$pdo = new PDO(
|
||||
'mysql:host=localhost;dbname=pwtool;charset=utf8',
|
||||
'pwtool',
|
||||
'BaVYtU9YqMyrp4qi',
|
||||
[PDO::ATTR_EMULATE_PREPARES => 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.<br/>';
|
||||
echo 'In case you are the administrator of this page, ';
|
||||
echo 'please check if random keys are stored correct.<br/>';
|
||||
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 '<p>Password insert succeeded. Here\'s the URL to fetch it:</p>';
|
||||
print '<p><a href="'.dirname($_SERVER['PHP_SELF']).'?key='.$myKey->code.'">link</a></p>';
|
||||
|
||||
}
|
||||
else{
|
||||
//print '<p>Nope, not here: '.$adminPassword.'</p>';
|
||||
echo 'You entered the wrong captcah. Aren\'t you human?';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($displayForm){
|
||||
|
||||
?>
|
||||
<form method="post" action="add.php">
|
||||
<table border="0" cellspacing="2" cellpadding="2">
|
||||
<?php /*<tr>
|
||||
<td>Admin Password:</td><td><input type="password" name="adminPassword" value="" /></td>
|
||||
</tr> */ ?>
|
||||
<tr>
|
||||
<td>
|
||||
<input type="hidden" name="random" value="<?= $captchas->random () ?>" />
|
||||
<?php //Your message:</td><td><input name="message" value="Hello World" size="60" /> ?>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
</td>
|
||||
<td>
|
||||
<?= $captchas->image () ?> </br><a href="javascript:captchas_image_reload('captchas.net')">Reload Image</a>
|
||||
<?php /*<br> <a href="<?= $captchas->audio_url () ?>">Phonetic spelling (mp3)</a>
|
||||
<br> <a href="<?= $captchas->audio_url () ?>&language=de">Buchstabieren (mp3)</a>
|
||||
<br> <a href="<?= $captchas->audio_url () ?>&language=it">Compitare (mp3)</a>
|
||||
<br> <a href="<?= $captchas->audio_url () ?>&language=nl">Spellen (mp3)</a>
|
||||
<br> <a href="<?= $captchas->audio_url () ?>&language=fr">Epeler (mp3)</a> */ ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
The CAPTCHA:
|
||||
</td>
|
||||
<td>
|
||||
<input name="password" size="6" />
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>New Password:</td><td><input type="text" name="newPassword" value="" /></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"><input type="submit" name="submit" value="Submit" /></td>
|
||||
</tr>
|
||||
</table>
|
||||
</form>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<br /><br />
|
||||
</body>
|
||||
</html>
|
||||
53
index.php
53
index.php
|
|
@ -28,8 +28,8 @@
|
|||
} catch (PDOException $failure) {
|
||||
echo "Connection failed: " . $failure->getMessage();
|
||||
};
|
||||
require 'CaptchasDotNet.php';
|
||||
|
||||
require 'CaptchasDotNet.php';
|
||||
$captchas = new CaptchasDotNet ('demo', 'secret',
|
||||
'/tmp/captchasnet-random-strings','3600',
|
||||
'abcdefghkmnopqrstuvwxyz','6',
|
||||
|
|
@ -84,10 +84,57 @@
|
|||
else{
|
||||
print '<p><strong>Error:</strong> You need to supply a valid key.</p>';
|
||||
}
|
||||
} else
|
||||
}
|
||||
elseif(isset($_REQUEST['random']))
|
||||
{ //captcah was used, process it
|
||||
|
||||
$captchas = new CaptchasDotNet ('demo', 'secret',
|
||||
'/tmp/captchasnet-random-strings','3600',
|
||||
'abcdefghkmnopqrstuvwxyz','6',
|
||||
'240','80','000088');
|
||||
|
||||
// Read the form values
|
||||
$password = $_REQUEST['password'];
|
||||
$random_string = $_REQUEST['random'];
|
||||
|
||||
$newPassword = str_replace("'", '', trim($_POST['newPassword']));
|
||||
|
||||
if (!$captchas->validate ($random_string))
|
||||
{ // captcah error
|
||||
echo 'The session key (random) does not exist, please go back and reload form.<br/>';
|
||||
echo 'In case you are the administrator of this page, ';
|
||||
echo 'please check if random keys are stored correct.<br/>';
|
||||
echo 'See http://captchas.net/sample/php/ "Problems with save mode"';
|
||||
}
|
||||
elseif ($captchas->verify ($password))
|
||||
{ //captcah passes, add password to DB
|
||||
$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 '<p>Password insert succeeded. Here\'s the URL to fetch it:</p>';
|
||||
print '<p><a href="'.dirname($_SERVER['PHP_SELF']).'?key='.$myKey->code.'">link</a></p>';
|
||||
|
||||
}
|
||||
else
|
||||
{ //captcah worng
|
||||
//print '<p>Nope, not here: '.$adminPassword.'</p>';
|
||||
echo 'You entered the wrong captcah. Aren\'t you human?';
|
||||
}
|
||||
}
|
||||
else
|
||||
{ //Display New password entry form
|
||||
?>
|
||||
<form method="post" action="add.php">
|
||||
<form method="post" >
|
||||
<table border="0" cellspacing="2" cellpadding="2">
|
||||
<?php /*<tr>
|
||||
<td>Admin Password:</td><td><input type="password" name="adminPassword" value="" /></td>
|
||||
|
|
|
|||
Loading…
Reference in New Issue