diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index e8a45efcd62..fecbafe1dba 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -238,9 +238,10 @@ class User extends CommonObject * @param string $sid If defined, sid to used for search * @param int $loadpersonalconf 1=also load personal conf of user (in $user->conf->xxx), 0=do not load personal conf. * @param int $entity If a value is >= 0, we force the search on a specific entity. If -1, means search depens on default setup. + * @param int $email If defined, email to used for search * @return int <0 if KO, 0 not found, >0 if OK */ - public function fetch($id = '', $login = '', $sid = '', $loadpersonalconf = 0, $entity = -1) + public function fetch($id = '', $login = '', $sid = '', $loadpersonalconf = 0, $entity = -1, $email = '') { global $conf, $user; @@ -305,6 +306,10 @@ class User extends CommonObject { $sql.= " AND u.login = '".$this->db->escape($login)."'"; } + elseif ($email) + { + $sql.= " AND u.email = '".$this->db->escape($email)."'"; + } else { $sql.= " AND u.rowid = ".$id; diff --git a/htdocs/user/passwordforgotten.php b/htdocs/user/passwordforgotten.php index ada75da6110..8f85465cde2 100644 --- a/htdocs/user/passwordforgotten.php +++ b/htdocs/user/passwordforgotten.php @@ -45,8 +45,8 @@ $action=GETPOST('action', 'alpha'); $mode=$dolibarr_main_authentication; if (! $mode) $mode='http'; -$username = GETPOST('username', 'alpha'); -$passwordhash = GETPOST('passwordhash', 'alpha'); +$username = trim(GETPOST('username', 'alpha')); +$passwordhash = trim(GETPOST('passwordhash', 'alpha')); $conf->entity = (GETPOST('entity', 'int') ? GETPOST('entity', 'int') : 1); // Instantiate hooks of thirdparty module only if not already define @@ -104,6 +104,11 @@ if ($action == 'buildnewpassword' && $username) { $edituser = new User($db); $result=$edituser->fetch('', $username, '', 1); + if ($result == 0 && preg_match('/@/', $username)) + { + $result=$edituser->fetch('', '', '', 1, -1, $username); + } + if ($result <= 0 && $edituser->error == 'USERNOTFOUND') { $message = '