dolibarr 25.0.0-alpha
security2.lib.php File Reference

Set of function used for dolibarr security (not common functions). More...

Go to the source code of this file.

Functions

 dol_getwebuser ($mode)
 Return user/group account of web server.
 
 checkLoginPassEntity ($usertotest, $passwordtotest, $entitytotest, $authmode, $context='')
 Return a login if login/pass was successful.
 
if(!function_exists( 'dol_loginfunction')) makesalt ($type=CRYPT_SALT_LENGTH)
 Initialise the salt for the crypt function.
 
 encodedecode_dbpassconf ($level=0)
 Encode or decode database password in config file.
 
 isPasswordGenerationNoneForbidden ()
 Return if the 'none' password generation model (the one that applies no rule at all) is forbidden on this installation.
 
 getPasswordPatternMinLength ()
 Return the lowest value allowed for the minimum length (first field of USER_PASSWORD_PATTERN) of the 'Perso' password generation model.
 
 getRandomPassword ($generic=false, $replaceambiguouschars=null, $length=32)
 Return a generated password using default module.
 
 dolJSToSetRandomPassword ($htmlname, $htmlnameofbutton='generate_token', $generic=1)
 Output javascript to autoset a generated password using default module into a HTML element.
 
 showEyeForField ($htmlname, $htmlnameofinput)
 Output the eye picto to show/hide a password HTML field.
 

Detailed Description

Set of function used for dolibarr security (not common functions).

Warning, this file must not depends on other library files, except function.lib.php because it is used at low code level.

Definition in file security2.lib.php.

Function Documentation

◆ checkLoginPassEntity()

checkLoginPassEntity ( $usertotest,
$passwordtotest,
$entitytotest,
$authmode,
$context = '' )

Return a login if login/pass was successful.

Parameters
string$usertotestLogin value to test
string$passwordtotestPassword value to test
int | string$entitytotestInstance of data we must check
string[]$authmodeArray list of selected authentication mode array('http', 'dolibarr', 'xxx'...)
'api'|'dav'|'ws'|''$context Context checkLoginPassEntity was created for ('api', 'dav', 'ws', '')
Returns
string Login or '' or '–bad-login-validity–'

Show Dolibarr default login page. Part of this code is also duplicated into main.inc.php\top_htmlhead

Parameters
Translate$langsLang object (must be initialized by a new).
Conf$confConf object
Societe$mysocCompany object
Returns
void

Definition at line 59 of file security2.lib.php.

References $conf, $context, dol_buildpath(), dol_osencode(), and dol_syslog().

Referenced by check_authentication(), and Login\index().

◆ dol_getwebuser()

dol_getwebuser ( $mode)

Return user/group account of web server.

Parameters
string$mode'user' or 'group'
Returns
string Return user or group of web server

Definition at line 37 of file security2.lib.php.

◆ dolJSToSetRandomPassword()

dolJSToSetRandomPassword ( $htmlname,
$htmlnameofbutton = 'generate_token',
$generic = 1 )

Output javascript to autoset a generated password using default module into a HTML element.

Parameters
string$htmlnameHTML name of element to insert key into
string$htmlnameofbuttonHTML name of button
int$generic1=Return a generic pass, 0=Return a pass following setup rules
Returns
string HTML javascript code to set a password
See also
getRandomPassword()

Definition at line 612 of file security2.lib.php.

References $conf, and dol_escape_js().

Referenced by FormSetupItem\generateInputFieldSecureKey().

◆ encodedecode_dbpassconf()

encodedecode_dbpassconf ( $level = 0)

Encode or decode database password in config file.

Parameters
int$levelEncode level: 0 no encoding, 1 encoding
Returns
int Return integer <0 if KO, >0 if OK

Definition at line 372 of file security2.lib.php.

References conf(), dol_decode(), dol_syslog(), dolDecrypt(), and dolEncrypt().

◆ getPasswordPatternMinLength()

getPasswordPatternMinLength ( )

Return the lowest value allowed for the minimum length (first field of USER_PASSWORD_PATTERN) of the 'Perso' password generation model.

When the 'none' model is forbidden on this installation (see isPasswordGenerationNoneForbidden()), the Perso model must not be tuned down to a weak value either, so a floor of 10 characters is enforced in the admin screen, when saving the pattern, and at generation/validation time.

Returns
int Minimum allowed value for the Perso model minimum length

Definition at line 497 of file security2.lib.php.

References isPasswordGenerationNoneForbidden().

Referenced by modGeneratePassPerso\__construct().

◆ getRandomPassword()

getRandomPassword ( $generic = false,
$replaceambiguouschars = null,
$length = 32 )

Return a generated password using default module.

Parameters
bool$generictrue=Create a generic key (32 chars/numbers), false=Create a password using the configured password generation module.
?array<string>$replaceambiguouschars Discard ambiguous characters. For example: array('I').
int$lengthLength of random string (Used only if $generic is true)
Returns
string New value for password
See also
dol_hash(), dolJSToSetRandomPassword() @phan-suppress DolibarrForbiddenFunctionPlugin

Definition at line 512 of file security2.lib.php.

References $conf, dol_syslog(), getDolGlobalString(), and ModeleGenPassword\loadAndInstantiate().

Referenced by modEventOrganization\__construct(), modPropale\__construct(), addFileIntoDatabaseIndex(), ActionsAdherentCardCommon\assign_values(), ActionsContactCardCommon\assign_values(), CommonObject\getLastMainDocLink(), CommonObject\indexFile(), openid_connect_create_user(), Documents\post(), Adherent\setPassword(), and User\setPassword().

◆ isPasswordGenerationNoneForbidden()

isPasswordGenerationNoneForbidden ( )

Return if the 'none' password generation model (the one that applies no rule at all) is forbidden on this installation.

It is locked by the conf.php variable $dolibarr_main_restrict_password_generation_none (exposed as $conf->file->restrict_password_generation_none), which can only be changed by editing the config file on the server. When forbidden, the model is hidden from the admin screen, cannot be selected, and any value already set to 'none' falls back to the 'standard' model at generation/validation time.

Returns
int 1 if the 'none' model must not be used, 0 otherwise

Definition at line 481 of file security2.lib.php.

References $conf.

Referenced by getPasswordPatternMinLength(), modGeneratePassNone\isEnabled(), and ModeleGenPassword\loadAndInstantiate().

◆ makesalt()

if(!function_exists('dol_loginfunction')) makesalt ( $type = CRYPT_SALT_LENGTH)

Initialise the salt for the crypt function.

Parameters
int$type2 =>Return a salt for DES encryption 12=>Return a salt for MD5 encryption Undefined=>Return a salt for default encryption
Returns
string Salt string

Definition at line 335 of file security2.lib.php.

References dol_strlen(), and dol_syslog().

Referenced by MailmanSpip\add_to_spip().

◆ showEyeForField()

showEyeForField ( $htmlname,
$htmlnameofinput )

Output the eye picto to show/hide a password HTML field.

Parameters
string$htmlnameHTML name of element to insert key into
string$htmlnameofinputHTML id of input field
Returns
string HTML javascript code to set a password

Definition at line 651 of file security2.lib.php.