cvs: pearweb /include pear-format-html.php /public_html account-request.php /public_html/bugs bug.php

From: Date: Sat, 14 Aug 2004 15:25:41 +0000
Subject: cvs: pearweb /include pear-format-html.php /public_html account-request.php /public_html/bugs bug.php
Groups: php.pear.cvs php.pear.core 
Request: Send a blank email to pear-cvs+get-22900@lists.php.net to get a copy of this message
danielc Sat Aug 14 11:25:41 2004 EDT Modified files: /pearweb/include pear-format-html.php /pearweb/public_html account-request.php /pearweb/public_html/bugs bug.php Log: * Move CAPTCHA validation to a new function named validate_captcha(). http://cvs.php.net/diff.php/pearweb/include/pear-format-html.php?r1=1.144&r2=1.145&ty=u Index: pearweb/include/pear-format-html.php diff -u pearweb/include/pear-format-html.php:1.144 pearweb/include/pear-format-html.php:1.145 --- pearweb/include/pear-format-html.php:1.144 Tue Aug 10 18:10:19 2004 +++ pearweb/include/pear-format-html.php Sat Aug 14 11:25:40 2004 @@ -15,7 +15,7 @@ +----------------------------------------------------------------------+ | Authors: | +----------------------------------------------------------------------+ - $Id: pear-format-html.php,v 1.144 2004/08/10 22:10:19 danielc Exp $ + $Id: pear-format-html.php,v 1.145 2004/08/14 15:25:40 danielc Exp $ */ PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'error_handler'); @@ -962,17 +962,13 @@ /** * Sets <var>$_SESSION['captcha']</var> then produces a CAPTCHA image - * and form input + * and a form input element * * Only generate a new <var>$_SESSION['captcha']</var> if it doesn't exist * yet. This avoids the problem of the CAPTCHA value being changed but the * old image remaining in the browser's cache. This is necessary because * caching can not be reliably disabled. * - * If the user's submission doesn't match <var>$_SESSION['captcha']</var>, - * the form validation script in question should unset() - * <var>$_SESSION['captcha']</var>. This prevents brute force attacks. - * * Use upper case letters to reduce confusion with some of these fonts. * Input is passed through strtoupper() before comparison. * @@ -992,6 +988,34 @@ $out = 'Type &quot;' . $_SESSION['captcha'] . '&quot; into this box... '; $out .= '<input type="text" size="4" maxlength="4" name="captcha" />'; return $out; +} + +/** + * Check if the CAPTCHA value submitted by the user in + * <var>$_POST['captcha']</var> matches <var>$_SESSION['captcha']</var> + * + * If the two values don't match, this function will unset() + * <var>$_SESSION['captcha']</var>. Unsetting it will cause + * generate_captcha() to come up with a new CAPTCHA value and image. + * This prevents brute force attacks. + * + * Similarly, if the submission is correct <var>$_SESSION['captcha']</var> + * is unset() in order to keep robots from making multiple requests with + * a correctly guessed CAPTCHA value. + * + * @return bool true if input matches captcha, false if not + */ +function validate_captcha() { + if (!isset($_POST['captcha']) || + !isset($_SESSION['captcha']) || + $_SESSION['captcha'] != strtoupper($_POST['captcha'])) + { + unset($_SESSION['captcha']); + return false; + } else { + unset($_SESSION['captcha']); + return true; + } } ?> http://cvs.php.net/diff.php/pearweb/public_html/account-request.php?r1=1.44&r2=1.45&ty=u Index: pearweb/public_html/account-request.php diff -u pearweb/public_html/account-request.php:1.44 pearweb/public_html/account-request.php:1.45 --- pearweb/public_html/account-request.php:1.44 Fri Jul 23 15:49:33 2004 +++ pearweb/public_html/account-request.php Sat Aug 14 11:25:40 2004 @@ -15,7 +15,7 @@ +----------------------------------------------------------------------+ | Authors: | +----------------------------------------------------------------------+ - $Id: account-request.php,v 1.44 2004/07/23 19:49:33 danielc Exp $ + $Id: account-request.php,v 1.45 2004/08/14 15:25:40 danielc Exp $ */ require_once 'HTML/Form.php'; @@ -45,14 +45,9 @@ $display_form = true; } - if (!isset($_SESSION['captcha']) || - $_SESSION['captcha'] != strtoupper($_POST['captcha'])) - { - unset($_SESSION['captcha']); + if (!validate_captcha()) { $errors[] = 'Incorrect CAPTCHA'; $display_form = true; - } else { - unset($_SESSION['captcha']); } if ($errors) { http://cvs.php.net/diff.php/pearweb/public_html/bugs/bug.php?r1=1.62&r2=1.63&ty=u Index: pearweb/public_html/bugs/bug.php diff -u pearweb/public_html/bugs/bug.php:1.62 pearweb/public_html/bugs/bug.php:1.63 --- pearweb/public_html/bugs/bug.php:1.62 Fri Jul 23 15:49:33 2004 +++ pearweb/public_html/bugs/bug.php Sat Aug 14 11:25:40 2004 @@ -15,7 +15,7 @@ * @package Bugs * @copyright Copyright (c) 1997-2004 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License - * @version $Id: bug.php,v 1.62 2004/07/23 19:49:33 danielc Exp $ + * @version $Id: bug.php,v 1.63 2004/08/14 15:25:40 danielc Exp $ */ /* @@ -119,13 +119,8 @@ if ($_POST['in'] && $edit == 3) { // Submission of additional comment by others - if (!isset($_SESSION['captcha']) || - $_SESSION['captcha'] != strtoupper($_POST['captcha'])) - { - unset($_SESSION['captcha']); + if (!validate_captcha()) { $errors[] = 'Incorrect CAPTCHA'; - } else { - unset($_SESSION['captcha']); } if (!preg_match("/[.\\w+-]+@[.\\w-]+\\.\\w{2,}/i",

« previous php.pear.cvs (#22900) next »