function resetPassword(&$db, $passwordSendMethod = 'send_password_by_mail') { $retval = array('status' => tl::OK, 'password' => '', 'msg' => ''); $retval['status'] = $this->readFromDB($db); if ($retval['status'] >= tl::OK) { $retval['status'] = tlUser::E_EMAILLENGTH; if ($this->emailAddress != "") { $newPassword = tlUser::generatePassword(8, 4); $retval['status'] = $this->setPassword($newPassword); if ($retval['status'] >= tl::OK) { $retval['password'] = $newPassword; $mail_op = new stdClass(); $mail_op->status_ok = false; if ($passwordSendMethod == 'send_password_by_mail') { $mail_templates = config_get('mail_templates'); $admin_contact = config_get('admin_coordinates'); $tags = array('%admin_coordinates%', '%login_name%', '%password%', '%ipaddress%', '%timestamp%'); $values = array($admin_contact, $this->login, $newPassword, get_ip_address(), date("r", time())); // try to use localized template $file2get = str_replace('%locale%', $this->locale, $mail_templates->change_password); $msgBody = file_get_contents($file2get); if (is_null($msgBody)) { $msgBody = lang_get('change_password_mail_body'); } $msgBody = str_replace($tags, $values, $msgBody); $mail_op = @email_send(config_get('from_email'), $this->emailAddress, lang_get('mail_passwd_subject'), $msgBody); } if ($mail_op->status_ok || $passwordSendMethod == 'display_on_screen') { $retval['status'] = $this->writePasswordToDB($db); $retval['msg'] = 'ok'; } else { $retval['status'] = tl::ERROR; $retval['msg'] = $mail_op->msg; } } } } $retval['msg'] = $retval['msg'] != "" ? $retval['msg'] : $this->getUserErrorMessage($result['status']); return $retval; }
/** * reset user password in DB * * @param resource &$db reference to database handler * @param integer $userID * @param string $newPasswordSendMethod, default 'send_password_by_mail' * * @return hash * status: integer result status code * password: new password * msg: error message (if any) */ function resetPassword(&$db, $userID, $passwordSendMethod = 'send_password_by_mail') { $retval = array('status' => tl::OK, 'password' => '', 'msg' => ''); $user = new tlUser($userID); $retval['status'] = $user->readFromDB($db); // Reset can be done ONLY if user authentication method allows it. $doIt = false; if ($retval['status'] >= tl::OK) { $cfg = config_get('authentication'); $cfg = $cfg['domain']; $doIt = isset($cfg[$user->authentication]) && $cfg[$user->authentication]['allowPasswordManagement']; } if ($doIt) { $retval['status'] = tlUser::E_EMAILLENGTH; if (trim($user->emailAddress) != "") { $newPassword = tlUser::generatePassword(8, 4); $retval['status'] = $user->setPassword($newPassword, $cfg[$user->authentication]); if ($retval['status'] >= tl::OK) { $retval['password'] = $newPassword; $mail_op = new stdClass(); $mail_op->status_ok = false; if ($passwordSendMethod == 'send_password_by_mail') { $msgBody = lang_get('your_password_is') . "\n\n" . $newPassword . "\n\n" . lang_get('contact_admin'); $mail_op = @email_send(config_get('from_email'), $user->emailAddress, lang_get('mail_passwd_subject'), $msgBody); } if ($mail_op->status_ok || $passwordSendMethod == 'display_on_screen') { $retval['status'] = $user->writePasswordToDB($db); } else { $retval['status'] = tl::ERROR; $retval['msg'] = $mail_op->msg; } } } } $retval['msg'] = $retval['msg'] != "" ? $retval['msg'] : getUserErrorMessage($retval['status']); return $retval; }
/** * reset user password in DB * * @param resource &$db reference to database handler * @param integer $userID * @param string &$errorMsg reference to error message * * @return integer result status code */ function resetPassword(&$db, $userID, &$errorMsg) { $errorMsg = ''; $user = new tlUser($userID); $result = $user->readFromDB($db); if ($result >= tl::OK) { $result = tlUser::E_EMAILLENGTH; if ($user->emailAddress != "") { $newPassword = tlUser::generatePassword(8, 4); $result = $user->setPassword($newPassword); if ($result >= tl::OK) { // BUGID 3396 $msgBody = lang_get('your_password_is') . "\n\n" . $newPassword . "\n\n" . lang_get('contact_admin'); $mail_op = @email_send(config_get('from_email'), $user->emailAddress, lang_get('mail_passwd_subject'), $msgBody); if ($mail_op->status_ok) { $result = $user->writePasswordToDB($db); // BUGID 3396 } else { $result = tl::ERROR; $errorMsg = $mail_op->msg; } } } } $errorMsg = $errorMsg != "" ? $errorMsg : getUserErrorMessage($result); return $result; }