Skip to content

Commit 4eaee2c

Browse files
committed
MDL-30673 fix login autocompletion protection
1 parent 2117dcb commit 4eaee2c

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

blocks/login/block_login.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,27 @@ function get_content () {
3535
// TODO: now that we have multiauth it is hard to find out if there is a way to change password
3636
$forgot = $wwwroot . '/login/forgot_password.php';
3737

38+
if (empty($CFG->xmlstrictheaders) and !empty($CFG->loginpasswordautocomplete)) {
39+
$autocomplete = 'autocomplete="off"';
40+
} else {
41+
$autocomplete = '';
42+
}
43+
3844
$username = get_moodle_cookie();
3945

4046
$this->content->footer = '';
4147
$this->content->text = '';
4248

4349
if (!isloggedin() or isguestuser()) { // Show the block
4450

45-
$this->content->text .= "\n".'<form class="loginform" id="login" method="post" action="'.get_login_url().'">';
51+
$this->content->text .= "\n".'<form class="loginform" id="login" method="post" action="'.get_login_url().'" '.$autocomplete.'>';
4652

4753
$this->content->text .= '<div class="c1 fld username"><label for="login_username">'.get_string('username').'</label>';
4854
$this->content->text .= '<input type="text" name="username" id="login_username" value="'.s($username).'" /></div>';
4955

5056
$this->content->text .= '<div class="c1 fld password"><label for="login_password">'.get_string('password').'</label>';
5157

52-
if (!empty($CFG->loginpasswordautocomplete)) {
53-
$this->content->text .= '<input type="password" name="password" id="login_password" value="" autocomplete="off" /></div>';
54-
} else {
55-
$this->content->text .= '<input type="password" name="password" id="login_password" value="" /></div>';
56-
}
58+
$this->content->text .= '<input type="password" name="password" id="login_password" value="" '.$autocomplete.' /></div>';
5759

5860
if (isset($CFG->rememberusername) and $CFG->rememberusername == 2) {
5961
$checked = $username ? 'checked="checked"' : '';

lang/en/admin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@
613613
$string['loginhttps'] = 'Use HTTPS for logins';
614614
$string['loginpageautofocus'] = 'Autofocus login page form';
615615
$string['loginpageautofocus_help'] = 'Enabling this option improves usability of the login page, but automatically focusing fields may be considered an accessibility issue.';
616-
$string['loginpasswordautocomplete'] = 'Prevent password autocompletion on login form.';
616+
$string['loginpasswordautocomplete'] = 'Prevent password autocompletion on login form';
617617
$string['loginpasswordautocomplete_help'] = 'Having this off will let users save their account password in their browser. Switching this setting on will result in your site no longer following XHTML strict validation rules.';
618618
$string['loglifetime'] = 'Keep logs for';
619619
$string['longtimewarning'] = '<b>Please note that this process can take a long time.</b>';

login/index_form.html

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
} else {
55
$columns = 'onecolumn';
66
}
7+
8+
if (empty($CFG->xmlstrictheaders) and !empty($CFG->loginpasswordautocomplete)) {
9+
$autocomplete = 'autocomplete="off"';
10+
} else {
11+
$autocomplete = '';
12+
}
713
?>
814
<div class="loginbox clearfix <?php echo $columns ?>">
915
<div class="loginpanel">
@@ -29,7 +35,7 @@ <h2><?php print_string("returningtosite") ?></h2>
2935
echo '</div>';
3036
}
3137
?>
32-
<form action="<?php echo $CFG->httpswwwroot; ?>/login/index.php" method="post" id="login">
38+
<form action="<?php echo $CFG->httpswwwroot; ?>/login/index.php" method="post" id="login" <?php echo $autocomplete; ?> >
3339
<div class="loginform">
3440
<div class="form-label"><label for="username"><?php print_string("username") ?></label></div>
3541
<div class="form-input">
@@ -38,7 +44,7 @@ <h2><?php print_string("returningtosite") ?></h2>
3844
<div class="clearer"><!-- --></div>
3945
<div class="form-label"><label for="password"><?php print_string("password") ?></label></div>
4046
<div class="form-input">
41-
<input type="password" name="password" id="password" size="15" value="" <?php if (!empty($CFG->loginpasswordautocomplete)) {echo 'autocomplete="off"';} ?> />
47+
<input type="password" name="password" id="password" size="15" value="" <?php echo $autocomplete; ?> />
4248
<input type="submit" id="loginbtn" value="<?php print_string("login") ?>" />
4349
</div>
4450
<div class="clearer"><!-- --></div>

0 commit comments

Comments
 (0)