From 7978b4503dc6f0cd49be59d9b802f7f816c49cfa Mon Sep 17 00:00:00 2001 From: Andrelec1 <teddy.andreotti@supinfo.com> Date: Fri, 10 Oct 2014 14:57:07 +0200 Subject: [PATCH] Add function hideMail and use --- htdocs/core/lib/functions.lib.php | 36 +++++++++++++++++++++++++++++++ htdocs/user/passwordforgotten.php | 3 ++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 7097bd2abae..931c0b95fdd 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1224,6 +1224,42 @@ function dol_print_email($email,$cid=0,$socid=0,$addlink=0,$max=64,$showinvalid= return $newemail; } +/** + * Returns a hidden email. + * Hide part of email. + * + * @param string $mail Email + * @param string $replace Replacement caractaire ( defaul : *) + * @param int $nbreplace Number of replacement caractaire (default : 8) + * @param int $nbdisplaymail Number of caractaire unchanged (default: 4) + * @param int $nbdisplaydomain Number of caractaire unchanged of domain (default: 3) + * @param bool $displaytld Display tld (default: true) + * @return string Return hiden email or ''; + */ +function dol_hideMail($mail, $replace="*", $nbreplace=8, $nbdisplaymail=4, $nbdisplaydomain=3, $displaytld=true){ + if(!isValidEmail($mail))return ' '; + $tab = explode('@', $mail); + $tab2 = explode('.',$tab[1]); + $string_replace = ''; + $mail_name = $tab[0]; + $mail_domaine = $tab2[0]; + $mail_tld = $displaytld ? ".".$tab2[1] : " "; + + for($i=0; $i < $nbreplace; $i++){ + $string_replace .= $replace; + } + + if(strlen($mail_name) > $nbdisplaymail){ + $mail_name = substr($mail_name, 0, $nbdisplaymail); + } + + if(strlen($mail_domaine) > $nbdisplaydomain){ + $mail_domaine = substr($mail_domaine, strlen($mail_domaine)-$nbdisplaydomain); + } + + return $mail_name . $string_replace . $mail_domaine . $mail_tld; +} + /** * Show Skype link * diff --git a/htdocs/user/passwordforgotten.php b/htdocs/user/passwordforgotten.php index 4f1a36c6e04..c3c4fccb888 100644 --- a/htdocs/user/passwordforgotten.php +++ b/htdocs/user/passwordforgotten.php @@ -130,7 +130,8 @@ if ($action == 'buildnewpassword' && $username) // Success if ($edituser->send_password($user,$newpassword,1) > 0) { - $message = '<div class="ok">'.$langs->trans("PasswordChangeRequestSent",$edituser->login,$edituser->email).'</div>'; + + $message = '<div class="ok">'.$langs->trans("PasswordChangeRequestSent",$edituser->login,dol_hideMail($edituser->email)).'</div>'; //$message.=$newpassword; $username=''; } -- GitLab