Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement trim() to password input field #7661

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config/defaults.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -1409,3 +1409,7 @@
// 0 - Reply-All always
// 1 - Reply-List if mailing list is detected
$config['reply_all_mode'] = 0;

// Enables the trim of leading and trailing spaces in passwords during login and password plugin
// If enabled and existing users did use spaces in front or end of passwords, they cannot login
$config['trim_password'] = false;
8 changes: 7 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,22 @@
if ($RCMAIL->task == 'login' && $RCMAIL->action == 'login') {
$request_valid = $_SESSION['temp'] && $RCMAIL->check_request();
$pass_charset = $RCMAIL->config->get('password_charset', 'UTF-8');
$trim_password = $RCMAIL->config->get('trim_password', false);

// purge the session in case of new login when a session already exists
if ($request_valid) {
$RCMAIL->kill_session();
}

$password = rcube_utils::get_input_value('_pass', rcube_utils::INPUT_POST, true, $pass_charset);
if ($trim_password) {
$password = trim($password);
}

$auth = $RCMAIL->plugins->exec_hook('authenticate', array(
'host' => $RCMAIL->autoselect_host(),
'user' => trim(rcube_utils::get_input_value('_user', rcube_utils::INPUT_POST)),
'pass' => rcube_utils::get_input_value('_pass', rcube_utils::INPUT_POST, true, $pass_charset),
'pass' => $password,
'valid' => $request_valid,
'cookiecheck' => true,
));
Expand Down
6 changes: 6 additions & 0 deletions plugins/password/password.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ function password_save()
$confirm = $this->rc->config->get('password_confirm_current');
$required_length = intval($this->rc->config->get('password_minimum_length'));
$force_save = $this->rc->config->get('password_force_save');
$trim_password = $this->rc->config->get('trim_password', false);

if (($confirm && !isset($_POST['_curpasswd'])) || !isset($_POST['_newpasswd']) || !strlen($_POST['_newpasswd'])) {
$this->rc->output->command('display_message', $this->gettext('nopassword'), 'error');
Expand All @@ -158,6 +159,11 @@ function password_save()
$newpwd = rcube_charset::convert($newpwd, $rc_charset, $charset);
$conpwd = rcube_charset::convert($conpwd, $rc_charset, $charset);

if ($trim_password) {
$newpwd = trim($newpwd);
$conpwd = trim($conpwd);
}

if ($chk_pwd != $orig_pwd || preg_match('/[\x00-\x1F\x7F]/', $newpwd)) {
$this->rc->output->command('display_message', $this->gettext('passwordforbidden'), 'error');
}
Expand Down