function testController() { $stubRandomizer = $this->getMock('Randomizer'); $stubRandomizer->expects($this->any())->method('pattern')->will($this->returnValue(1)); $stubRandomizer->expects($this->any())->method('operator')->will($this->returnValue(1)); $stubRandomizer->expects($this->any())->method('operand')->will($this->returnValue(1)); $controller = new CaptchaController($stubRandomizer); $captcha = $controller->buildCaptcha(); $this->assertEquals("One + 1", $captcha->toString()); }
public function getValue() { try { return parent::getValue(); } catch (Exception $ex) { $ex->getMessage(); } }
$user = $_POST[AuthController::LOGIN_FORM_USER]; $pass = $_POST[AuthController::LOGIN_FORM_PASS]; //authenticate if (AuthController::is_authenticated($user, $pass)) { //save in session AuthController::save_auth($user); //redirect $redirect_url = !empty($_SESSION[AuthController::SESSION_REDIRECT_URL_KEY]) ? $_SESSION[AuthController::SESSION_REDIRECT_URL_KEY] : AuthController::LOGGED_IN_HOME_URL; http_response_code(302); header('Location: ' . $redirect_url); die; } else { //randomize sleep to timing string length attacks usleep(rand(AuthController::LOGIN_FAILED_TIMEOUT_MIN, AuthController::LOGIN_FAILED_TIMEOUT_MAX)); $flash = array(); $flash['class'] = 'danger'; $flash['message'] = 'Invalid username or password'; } } } } if (!empty($_REQUEST['logout']) && $_REQUEST['logout'] === 'true') { //log user out session_unset(); $flash = array(); $flash['class'] = 'info'; $flash['message'] = 'You have successfully logged out'; } $captcha_text = CaptchaController::generate_captcha(); //show login form include AuthController::VIEWS_PATH . 'login-page.php';
<?php /* Exemplo simples de uso */ include_once getcwd() . "/controller/CaptchaController.php"; $cc = new CaptchaController(); $cc->displayAction(); // Para escutar o captcha // $cc->audioPlayAction();