Files
dolibarr/htdocs/core/modules/security/captcha/modCaptchaStandard.class.php
Frédéric FRANCE 80171b5fe5 Update modCaptchaStandard.class.php (#31528)
* Update modCaptchaStandard.class.php

* Update modCaptchaStandard.class.php
2024-10-23 18:51:20 +02:00

110 lines
3.0 KiB
PHP

<?php
/* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* or see https://www.gnu.org/
*/
/**
* \file htdocs/core/modules/security/captcha/modCaptchaStandard.class.php
* \ingroup core
* \brief File to manage captcha generation according to dolibarr native code
*/
require_once DOL_DOCUMENT_ROOT.'/core/modules/security/captcha/modules_captcha.php';
require_once DOL_DOCUMENT_ROOT.'/core/modules/security/generate/modGeneratePassStandard.class.php';
/**
* Class to generate a password according to a dolibarr standard rule (12 random chars)
*/
class modCaptchaStandard extends ModeleCaptcha
{
/**
* @var string ID
*/
public $id;
public $picto = 'fa-shield-alt';
/**
* Constructor
*
* @param DoliDB $db Database handler
* @param Conf $conf Handler de conf
* @param Translate $langs Handler de langue
* @param User $user Handler du user connected
*/
public function __construct($db, $conf, $langs, $user)
{
$this->id = "standard";
$this->db = $db;
$this->conf = $conf;
$this->langs = $langs;
$this->user = $user;
}
/**
* Return description of module
*
* @return string Description of module
*/
public function getDescription()
{
global $langs;
return $langs->trans("DolibarrStandardCaptcha");
}
/**
* Return an example of password generated by this module
*
* @return string Example of password
*/
public function getExample()
{
global $db, $conf, $langs, $user;
$generator = new modGeneratePassStandard($db, $conf, $langs, $user);
$example = $generator->getExample();
$img = imagecreate(80, 32);
if (!$img) {
return "Problem with GD creation";
}
$background_color = imagecolorallocate($img, 250, 250, 250);
$ecriture_color = imagecolorallocate($img, 0, 0, 0);
imagestring($img, 4, 15, 8, $example, $ecriture_color);
ob_start();
imagepng($img);
$image_data = ob_get_contents();
ob_end_clean();
return '<img class="inline-block valignmiddle" src="data:image/png;base64,' . base64_encode($image_data) . '" border="0" width="80" height="32" />';
}
/**
* Validate a captcha
* This function is called after a log to validate a captcha, before validating a password.
*
* @return int 0 if KO, >0 if OK
*/
public function validateCodeAfterLoginSubmit()
{
return 1;
}
}