Skip to content

Commit

Permalink
2.11.19 Fix register.php
Browse files Browse the repository at this point in the history
  • Loading branch information
webpwnized committed Sep 29, 2024
1 parent 39eb7c9 commit 6110d89
Showing 1 changed file with 31 additions and 45 deletions.
76 changes: 31 additions & 45 deletions src/register.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
<?php
require_once (__SITE_ROOT__.'/classes/CSRFTokenHandler.php');
<?php
require_once __SITE_ROOT__.'/classes/CSRFTokenHandler.php';
$lCSRFTokenHandler = new CSRFTokenHandler($_SESSION["security-level"], "register-user");
$lHTMLControls = 'minlength="1" maxlength="15" required="required"';

switch ($_SESSION["security-level"]){
default: // Default case: This code is insecure
case "0": // This code is insecure
// DO NOTHING: This is equivalent to using client side security
$lEnableJavaScriptValidation = FALSE;
$lEnableHTMLControls = FALSE;
$lProtectAgainstMethodTampering = FALSE;
$lEncodeOutput = FALSE;
$lEnableJavaScriptValidation = false;
$lEnableHTMLControls = false;
$lProtectAgainstMethodTampering = false;
$lEncodeOutput = false;
break;

case "1": // This code is insecure
// DO NOTHING: This is equivalent to using client side security
$lEnableJavaScriptValidation = TRUE;
$lEnableHTMLControls = TRUE;
$lProtectAgainstMethodTampering = FALSE;
$lEncodeOutput = FALSE;
$lEnableJavaScriptValidation = true;
$lEnableHTMLControls = true;
$lProtectAgainstMethodTampering = false;
$lEncodeOutput = false;
break;

case "2":
Expand All @@ -27,10 +29,10 @@
* Concerning SQL Injection, use parameterized stored procedures. Parameterized
* queries is not good enough. You cannot use least privilege with queries.
*/
$lEnableJavaScriptValidation = TRUE;
$lEnableHTMLControls = TRUE;
$lProtectAgainstMethodTampering = TRUE;
$lEncodeOutput = TRUE;
$lEnableJavaScriptValidation = true;
$lEnableHTMLControls = true;
$lProtectAgainstMethodTampering = true;
$lEncodeOutput = true;
break;
}// end switch

Expand All @@ -40,13 +42,13 @@

<div class="page-title">Register for an Account</div>

<?php include_once (__SITE_ROOT__.'/includes/back-button.inc');?>
<?php include_once (__SITE_ROOT__.'/includes/hints/hints-menu-wrapper.inc'); ?>
<?php include_once __SITE_ROOT__.'/includes/back-button.inc';?>
<?php include_once __SITE_ROOT__.'/includes/hints/hints-menu-wrapper.inc'; ?>

<?php
if ($lFormSubmitted){

try {
try {
$lValidationFailed = false;

if ($lProtectAgainstMethodTampering) {
Expand Down Expand Up @@ -77,37 +79,33 @@
}// end if

if (strlen($lUsername) == 0) {
$lValidationFailed = TRUE;
$lValidationFailed = true;
echo '<h2 class="error-message">Username cannot be blank</h2>';
}// end if

if ($lPassword != $lConfirmedPassword ) {
$lValidationFailed = TRUE;
$lValidationFailed = true;
echo '<h2 class="error-message">Passwords do not match</h2>';
}// end if

if (!$lValidationFailed){
if (!$lValidationFailed){
$lRowsAffected = $SQLQueryHandler->insertNewUserAccount($lUsername, $lPassword, $lUserSignature);
echo '<h2 class="success-message">Account created for ' . $lUsernameText .'. '.$lRowsAffected.' rows inserted.</h2>';
$LogHandler->writeToLog("Added account for: " . $lUsername);
}// end if (!$lValidationFailed)

} catch (Exception $e) {
echo $CustomErrorHandler->FormatError($e, "Failed to add account");
$LogHandler->writeToLog("Failed to add account for: " . $lUsername);
$LogHandler->writeToLog("Failed to add account for: " . $lUsername);
}// end try

}// end if $lFormSubmitted
?>

<script type="text/javascript">
<!--
<?php
if($lEnableJavaScriptValidation){
echo "var lValidateInput = \"TRUE\"" . PHP_EOL;
}else{
echo "var lValidateInput = \"FALSE\"" . PHP_EOL;
}// end if
<?php
echo "var lValidateInput = \"" . ($lEnableJavaScriptValidation ? "TRUE" : "FALSE") . "\"" . PHP_EOL;
?>

function onSubmitOfForm(/*HTMLFormElement*/ theForm){
Expand Down Expand Up @@ -136,7 +134,7 @@ function onSubmitOfForm(/*HTMLFormElement*/ theForm){

<span>
<a style="text-decoration: none; cursor: pointer;" href="./webservices/rest/ws-user-account.php">
<img style="vertical-align: middle;" src="./images/ajax_logo-75-79.jpg" height="75px" width="78px" />
<img style="vertical-align: middle;" src="./images/ajax_logo-75-79.jpg" height="75px" width="78px" alt="AJAX" />
<span style="font-weight:bold;">Switch to RESTful Web Service Version of this Page</span>
</a>
</span>
Expand All @@ -156,23 +154,15 @@ function onSubmitOfForm(/*HTMLFormElement*/ theForm){
<td class="label">Username</td>
<td>
<input type="text" name="username" size="15" autofocus="autofocus"
<?php
if ($lEnableHTMLControls) {
echo('minlength="1" maxlength="15" required="required"');
}// end if
?>
<?php if ($lEnableHTMLControls) { echo $lHTMLControls; }?>
/>
</td>
</tr>
<tr>
<td class="label">Password</td>
<td>
<input type="password" name="password" size="15"
<?php
if ($lEnableHTMLControls) {
echo('minlength="1" maxlength="15" required="required"');
}// end if
?>
<?php if ($lEnableHTMLControls) { echo $lHTMLControls; }?>
/>
&nbsp;
<a href="index.php?page=password-generator.php&username=<?php echo $logged_in_user ?>" target="_blank">Password Generator</a>
Expand All @@ -182,11 +172,7 @@ function onSubmitOfForm(/*HTMLFormElement*/ theForm){
<td class="label">Confirm Password</td>
<td>
<input type="password" name="confirm_password" size="15"
<?php
if ($lEnableHTMLControls) {
echo('minlength="1" maxlength="15" required="required"');
}// end if
?>
<?php if ($lEnableHTMLControls) { echo $lHTMLControls; }?>
/>
</td>
</tr>
Expand All @@ -196,12 +182,12 @@ function onSubmitOfForm(/*HTMLFormElement*/ theForm){
<textarea rows="3" cols="50" name="my_signature"
<?php
if ($lEnableHTMLControls) {
echo('minlength="1" maxlength="100" required="required"');
echo 'minlength="1" maxlength="100" required="required"';
}// end if
?>
></textarea>
</td>
</tr>
</tr>
<tr><td>&nbsp;</td></tr>
<tr>
<td colspan="2" style="text-align:center;">
Expand Down

0 comments on commit 6110d89

Please sign in to comment.