@ -9,17 +9,42 @@
if (!defined("_ECRIRE_INC_VERSION")) return;
function facteur_affiche_password_masque($pass){
$l = strlen($pass);
if ($l< =8){
return str_pad('',$l,'*');
/**
* Afficher partiellement un mot de passe que l'on ne veut pas rendre lisible par un champ hidden
* @param string $passe
* @param bool $afficher_partiellement
* @param int|null $portion_pourcent
* @return string
*/
function facteur_affiche_password_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) {
if (function_exists('spip_affiche_mot_de_passe_masque')) {
return spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement, $portion_pourcent);
}
$l = strlen($passe);
if ($l< =8 or !$afficher_partiellement){
if (!$l) {
return ''; // montrer qu'il y a pas de mot de passe si il y en a pas
}
return str_pad('',$afficher_partiellement ? $l : 16,'*');
}
if (is_null($portion_pourcent)) {
if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) {
define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20%
}
$portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT;
}
if ($portion_pourcent >= 100) {
return $passe;
}
$e = intval(ceil($l/10));
$e = intval(ceil($l * $portion_pourcent / 100 / 2));
$e = max($e, 0);
$mid = str_pad('',$l-2*$e,'*');
if (strlen($mid)>8){
if ($e>0 and strlen($mid)>8){
$mid = '***...***';
}
return substr($pass,0,$e) . $mid . substr($pass,-$e);
return substr($passe ,0,$e) . $mid . ($e > 0 ? substr($passe ,-$e) : '' );
}
/**