Skip to content

Commit

Permalink
Improve passwords autocomplete
Browse files Browse the repository at this point in the history
Use `autocomplete="new-password"` or `autocomplete="current-password"` to better signal to browsers and password managers how to handle the password fields.

This feature is especially useful for “change your password” and “new user” forms
  • Loading branch information
Gustavo Bazan authored and tegon committed Apr 19, 2018
1 parent 45481df commit 6260c29
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
### Unreleased

* enhancements
* Add `autocomplete="new-password"` to new password fields (by @gssbzn)
* Add `autocomplete="current-password"` to current password fields (by @gssbzn)

### 4.4.3 - 2018-03-17

* bug fixes
Expand Down Expand Up @@ -44,7 +48,7 @@
* Validations were being ignored on singup in the `Trackable#update_tracked_fields!` method. (by @AshleyFoster)
* Do not modify options for `#serializable_hash`. (by @guigs)
* Email confirmations were being sent on sign in/sign out for application using `mongoid` and `mongoid-paperclip` gems. This is because previously we were checking if a model is from Active Record by checking if the method `after_commit` was defined - since `mongoid` doesn' have one - but `mongoid-paperclip` gem does define one, which cause this issue. (by @fjg)

### 4.3.0 - 2017-05-14

* Enhancements
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/passwords/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em><br />
<% end %>
<%= f.password_field :password, autofocus: true, autocomplete: "off" %>
<%= f.password_field :password, autofocus: true, autocomplete: "new-password" %>

This comment has been minimized.

Copy link
@kylefox

kylefox Nov 13, 2018

@gssbzn @tegon Should the :password_confirmation field also be changed to autocomplete: "new-password"?

This comment has been minimized.

Copy link
@gssbzn

gssbzn Nov 13, 2018

I decided to leave :password_confirmation as it was considering that the documentation for new-password says it is to offer assistance in creating a new password, and I wasn't sure if this is something should apply for the confirmation
This was my point of view then and there's no much documentation about it

This comment has been minimized.

Copy link
@tegon

tegon Nov 13, 2018

Member

Probably, since it was changed in registrations/edit and registrations/new.
It seems like we forgot about this one. Do you want to send a PR with this change? I can do it here if not.

</div>

<div class="field">
Expand Down
6 changes: 3 additions & 3 deletions app/views/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<div class="field">
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, autocomplete: "off" %>
<%= f.password_field :password, autocomplete: "new-password" %>
<% if @minimum_password_length %>
<br />
<em><%= @minimum_password_length %> characters minimum</em>
Expand All @@ -23,12 +23,12 @@

<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
<%= f.password_field :password_confirmation, autocomplete: "new-password" %>
</div>

<div class="field">
<%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password, autocomplete: "off" %>
<%= f.password_field :current_password, autocomplete: "current-password" %>
</div>

<div class="actions">
Expand Down
4 changes: 2 additions & 2 deletions app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "off" %>
<%= f.password_field :password, autocomplete: "new-password" %>
</div>

<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
<%= f.password_field :password_confirmation, autocomplete: "new-password" %>
</div>

<div class="actions">
Expand Down
2 changes: 1 addition & 1 deletion app/views/devise/sessions/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password, autocomplete: "off" %>
<%= f.password_field :password, autocomplete: "current-password" %>
</div>

<% if devise_mapping.rememberable? -%>
Expand Down

0 comments on commit 6260c29

Please sign in to comment.