27require_once DOL_DOCUMENT_ROOT.
'/core/modules/security/captcha/modules_captcha.php';
28require_once DOL_DOCUMENT_ROOT.
'/core/modules/security/generate/modGeneratePassStandard.class.php';
44 public $picto =
'fa-shield-alt';
49 public $position = 10;
62 $this->
id = strtolower(preg_replace(
'/^modCaptcha/i',
'', get_class($this)));
66 $this->langs = $langs;
78 return $langs->trans(
"DolibarrStandardCaptcha");
88 global $db, $conf, $langs, $user;
91 $generator->length =
'5';
92 $example = $generator->getExample();
94 if (function_exists(
"imagecreate") && function_exists(
"imagepng")) {
95 $img = imagecreate(80, 32);
97 return "Problem with GD creation";
99 $background_color = imagecolorallocate($img, 250, 250, 250);
100 $ecriture_color = imagecolorallocate($img, 0, 0, 0);
101 imagestring($img, 4, 15, 8, $example, $ecriture_color);
105 $image_data = ob_get_contents();
108 return '<img class="inline-block valignmiddle" src="data:image/png;base64,' . base64_encode($image_data) .
'" border="0" width="80" height="32" />';
111 $image_data_base64 =
'iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAFElEQVR4nGNsaGhgwA2Y8MiNYGkA22EBlPG3fjQAAAAASUVORK5CYII=';
112 return '<img class="inline-block valignmiddle" src="data:image/png;base64,' . $image_data_base64 .
'" border="0" width="80" height="32" />';
126 $idofbutton =
"actionlogin";
132 $out =
'<!-- Captcha -->
133 <div class="trinputlogin">
134 <div class="tagtd tdinputlogin nowrap none valignmiddle">
136 <span class="fa fa-unlock"></span>
137 <span class="nofa span-icon-security inline-block">
138 <input id="securitycode" placeholder="'.$langs->trans(
"SecurityCode").
'" class="flat input-icon-security width125" type="text" maxlength="5" name="code" tabindex="3" autocomplete="off" />
140 <span class="nowrap inline-block">
141 <img class="inline-block valignmiddle" src="'.DOL_URL_ROOT.
'/core/antispamimage.php" border="0" width="80" height="32" id="img_securitycode" />
142 <a class="inline-block valignmiddle" href="'.$php_self.
'" tabindex="4" data-role="button" onclick="submitFormFromCaptcha(event)">'.
img_picto($langs->trans(
"Refresh"),
'refresh',
'id="captcha_refresh_img"').
'</a>
149 function submitFormFromCaptcha(event) {
150 console.log("submitFormFromCaptcha");
152 // Prevent the default action of the link
153 event.preventDefault();
155 const form = event.target.closest("form");
157 // Submit the form if found
159 console.log(\'we set '.
dol_escape_js($idofbutton).
' to value "disabled" if found\'); /* TODO Why this ? #actionlogn seems to not exists */
160 elementid = document.getElementById(\''.
dol_escape_js($idofbutton).
'\');
161 console.log(elementid);
163 elementid.value =
"disabled";
170 <!-- End code
for Captcha -->
'."\n";
183 public function validateCodeAfterLoginSubmit()
185 $sessionkey = 'dol_antispam_value
'; // The same key than set into the /core/antispamimage.php file.
187 $ok = (array_key_exists($sessionkey, $_SESSION) && (strtolower($_SESSION[$sessionkey]) === strtolower(GETPOST('code
', 'restricthtml
')))) ? 1 : 0;
Parent class for password rules/management modules.
Class to generate a password according to a dolibarr standard rule (12 random chars)
getCaptchaCodeForForm($php_self='')
Return the HTML content to output on a form that need the captcha.
__construct($db, $conf, $langs, $user)
Constructor.
getDescription()
Return description of module.
getExample()
Return an example of password generated by this module.
Class to generate a password according to a dolibarr standard rule (12 random chars)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
conf($dolibarr_main_document_root)
Load conf file (file must exists)
$conf db user
Active Directory does not allow anonymous connections.