From e91a93667726ea9d5505f4c6ba2b847b3995cfdb Mon Sep 17 00:00:00 2001 From: Aaron Johnson Date: Sat, 26 Mar 2022 06:08:28 -0500 Subject: [PATCH] Single file processing --- add.php | 164 ------------------------------------------------------ index.php | 53 +++++++++++++++++- 2 files changed, 50 insertions(+), 167 deletions(-) delete mode 100755 add.php diff --git a/add.php b/add.php deleted file mode 100755 index e97539b..0000000 --- a/add.php +++ /dev/null @@ -1,164 +0,0 @@ - - - - - - Password Fetch tool - - - -

-
-
-One Time Password Retrieval Tool -
-
- 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){ - -?> -
- - - - */ ?> - - - - - - - - - - - - - - - - - - - -
Admin Password:
- - ?> -
- - image () ?>
Reload Image - Phonetic spelling (mp3) -
Buchstabieren (mp3) -
Compitare (mp3) -
Spellen (mp3) -
Epeler (mp3) */ ?> -
- The CAPTCHA: - - -
New Password:
-
- -
-
-

- - diff --git a/index.php b/index.php index 2488a92..b44fa80 100755 --- a/index.php +++ b/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 '

Error: You need to supply a valid key.

'; } - } 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.
'; + 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)) + { //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 '

Password insert succeeded. Here\'s the URL to fetch it:

'; + print '

link

'; + + } + else + { //captcah worng + //print '

Nope, not here: '.$adminPassword.'

'; + echo 'You entered the wrong captcah. Aren\'t you human?'; + } + } + else { //Display New password entry form ?> -
+
Admin Password: