/usr/share/php/Text/CAPTCHA/Driver/Word.php is in php-text-captcha 0.4.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | <?php
/**
* Text_CAPTCHA_Driver_Word - Text_CAPTCHA driver word CAPTCHAs
*
* Class to create a textual Turing test
*
* @author Tobias Schlitt <schlitt@php.net>
* @author Christian Wenz <wenz@php.net>
* @license BSD License
*/
/**
*
* Require Numbers_Words class for generating the text.
*
*/
require_once 'Text/CAPTCHA.php';
require_once 'Numbers/Words.php';
class Text_CAPTCHA_Driver_Word extends Text_CAPTCHA
{
/**
* Phrase length
*
* This variable holds the length of the Word
*
* @access private
*/
var $_length;
/**
* Numbers_Words mode
*
* This variable holds the mode for Numbers_Words
*
* @access private
*/
var $_mode;
/**
* Locale
*
* This variable holds the locale for Numbers_Words
*
* @access private
*/
var $_locale;
/**
* init function
*
* Initializes the new Text_CAPTCHA_Driver_Word object
*
* @param array $options CAPTCHA options with these keys:
* phrase The "secret word" of the CAPTCHA
* length The number of characters in the phrase
* locale The locale for Numbers_Words
* mode The mode for Numbers_Words
*
* @access public
*/
function init($options = array())
{
if (isset($options['length']) && is_int($options['length'])) {
$this->_length = $options['length'];
} else {
$this->_length = 4;
}
if (isset($options['phrase']) && !empty($options['phrase'])) {
$this->_phrase = (string)(int)$options['phrase'];
} else {
$this->_createPhrase();
}
if (isset($options['mode']) && !empty($options['mode'])) {
$this->_mode = $options['mode'];
} else {
$this->_mode = 'single';
}
if (isset($options['locale']) && !empty($options['locale'])) {
$this->_locale = $options['locale'];
} else {
$this->_locale = 'en_US';
}
}
/**
* Create random CAPTCHA phrase, "Word edition" (numbers only)
*
* This method creates a random phrase
*
* @access private
*/
function _createPhrase()
{
$this->_phrase = (string)Text_Password::create($this->_length, 'unpronounceable', 'numeric');
}
/**
* Return CAPTCHA as a string
*
* This method returns the CAPTCHA as string
*
* @access public
* @return text string
*/
function getCAPTCHA()
{
$res = '';
if ($this->_mode == 'single') {
for ($i = 0; $i < strlen($this->_phrase); $i++) {
$res .= ' '.Numbers_Words::toWords($this->_phrase{$i}, $this->_locale);
}
} else {
$res = Numbers_Words::toWords($this->_phrase, $this->_locale);
}
return $res;
}
}
|