From 7978b4503dc6f0cd49be59d9b802f7f816c49cfa Mon Sep 17 00:00:00 2001 From: Andrelec1 Date: Fri, 10 Oct 2014 14:57:07 +0200 Subject: [PATCH 1/4] 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 = '
'.$langs->trans("PasswordChangeRequestSent",$edituser->login,$edituser->email).'
'; + + $message = '
'.$langs->trans("PasswordChangeRequestSent",$edituser->login,dol_hideMail($edituser->email)).'
'; //$message.=$newpassword; $username=''; } From f4f1f45d5a0da2124662a517666054183b43e242 Mon Sep 17 00:00:00 2001 From: Andrelec1 Date: Fri, 10 Oct 2014 15:01:10 +0200 Subject: [PATCH 2/4] copyright and annotation --- htdocs/core/lib/functions.lib.php | 13 +++++++------ htdocs/user/passwordforgotten.php | 1 + 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 931c0b95fdd..28695fa41f4 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -11,6 +11,7 @@ * Copyright (C) 2013 Cédric Salvador * Copyright (C) 2013 Alexandre Spangaro * Copyright (C) 2014 Marcos García + * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com> * * 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 @@ -1229,15 +1230,15 @@ function dol_print_email($email,$cid=0,$socid=0,$addlink=0,$max=64,$showinvalid= * 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 string $replace Replacement character ( defaul : *) + * @param int $nbreplace Number of replacement character (default : 8) + * @param int $nbdisplaymail Number of character unchanged (default: 4) + * @param int $nbdisplaydomain Number of character unchanged of domain (default: 3) * @param bool $displaytld Display tld (default: true) - * @return string Return hiden email or ''; + * @return string Return hidden email or ''; */ function dol_hideMail($mail, $replace="*", $nbreplace=8, $nbdisplaymail=4, $nbdisplaydomain=3, $displaytld=true){ - if(!isValidEmail($mail))return ' '; + if(!isValidEmail($mail))return ''; $tab = explode('@', $mail); $tab2 = explode('.',$tab[1]); $string_replace = ''; diff --git a/htdocs/user/passwordforgotten.php b/htdocs/user/passwordforgotten.php index c3c4fccb888..eccd3d0cda3 100644 --- a/htdocs/user/passwordforgotten.php +++ b/htdocs/user/passwordforgotten.php @@ -2,6 +2,7 @@ /* Copyright (C) 2007-2011 Laurent Destailleur * Copyright (C) 2008-2012 Regis Houssin * Copyright (C) 2008-2011 Juanjo Menent + * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com> * * 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 From 269b960d9a6127380677c27e1f618d369e49f8a9 Mon Sep 17 00:00:00 2001 From: Andrelec1 Date: Fri, 10 Oct 2014 15:18:24 +0200 Subject: [PATCH 3/4] Add support tld with dots --- htdocs/core/lib/functions.lib.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 28695fa41f4..9dd4bb4da6b 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1244,7 +1244,11 @@ function dol_hideMail($mail, $replace="*", $nbreplace=8, $nbdisplaymail=4, $nbdi $string_replace = ''; $mail_name = $tab[0]; $mail_domaine = $tab2[0]; - $mail_tld = $displaytld ? ".".$tab2[1] : " "; + $mail_tld = ''; + + for($i=1; $i < count($tab2) && $displaytld ;$i++){ + $mail_tld .= '.'.$tab2[$i]; + } for($i=0; $i < $nbreplace; $i++){ $string_replace .= $replace; From 52e1bd2ad1353c9acdce74e2a22ac2e4b6fe9fc4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 11 Oct 2014 23:46:49 +0200 Subject: [PATCH 4/4] Merge --- htdocs/core/lib/functions2.lib.php | 82 +++++++++++++++--------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index ba1cc230258..e6f6228eec9 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -480,47 +480,47 @@ function clean_url($url,$http=1) } - -/** - * Returns an email value with obfuscated parts. - * - * @param string $mail Email - * @param string $replace Replacement character (defaul : *) - * @param int $nbreplace Number of replacement character (default : 8) - * @param int $nbdisplaymail Number of character unchanged (default: 4) - * @param int $nbdisplaydomain Number of character unchanged of domain (default: 3) - * @param bool $displaytld Display tld (default: true) - * @return string Return email with hidden parts or ''; - */ -function dolObfuscateEmail($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 = ''; - - for($i=1; $i < count($tab2) && $displaytld ;$i++) - { - $mail_tld .= '.'.$tab2[$i]; - } - - 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; -} + +/** + * Returns an email value with obfuscated parts. + * + * @param string $mail Email + * @param string $replace Replacement character (defaul : *) + * @param int $nbreplace Number of replacement character (default : 8) + * @param int $nbdisplaymail Number of character unchanged (default: 4) + * @param int $nbdisplaydomain Number of character unchanged of domain (default: 3) + * @param bool $displaytld Display tld (default: true) + * @return string Return email with hidden parts or ''; + */ +function dolObfuscateEmail($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 = ''; + + for($i=1; $i < count($tab2) && $displaytld ;$i++) + { + $mail_tld .= '.'.$tab2[$i]; + } + + 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; +} /**