diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index e088f764040..5f9c1c4f328 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -10,7 +10,7 @@ * Copyright (C) 2010-2014 Juanjo Menent * Copyright (C) 2013 Cédric Salvador * Copyright (C) 2013 Alexandre Spangaro - * Copyright (C) 2014 Marcos García + * Copyright (C) 2014 Marcos García * Copyright (C) 2014 Cédric GROSS * * This program is free software; you can redistribute it and/or modify diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 746755b824c..e6f6228eec9 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2008-2014 Laurent Destailleur * Copyright (C) 2008-2012 Regis Houssin * Copyright (C) 2008 Raphael Bertrand (Resultic) * Copyright (C) 2014 Marcos García @@ -479,6 +479,50 @@ function clean_url($url,$http=1) else return $url; } + + +/** + * 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; +} + + /** * Return lines of an html table from an array * Used by array2table function only diff --git a/htdocs/user/passwordforgotten.php b/htdocs/user/passwordforgotten.php index 4f1a36c6e04..4d7422109bf 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 @@ -27,8 +28,8 @@ define("NOLOGIN",1); // This means this output page does not require to be logge require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php'; -if (! empty($conf->ldap->enabled)) - require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; +if (! empty($conf->ldap->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php'; $langs->load("errors"); $langs->load("users"); @@ -130,7 +131,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,dolObfuscateEmail($edituser->email)).'
'; //$message.=$newpassword; $username=''; }