html5 now has some new attribute values for the autocomplete
attribute to assist user-agents when autofilling forms. One of the new values, new-password
, is used to tell the user agent to enter a new password, opposed to the user's current password.
What's not clear to me though, is how to properly tell it to generate the same password for both fields when your form makes the user enter the new password twice as a confirmation? Maybe by using the same custom section-*
prefix on both inputs, such as autocomplete="new-password section-my-new-pw"
? The spec mentions the section-*
prefix will affect the autofill scope, but it's not overly specific about what that means for my case.
Here's a sample form that I imagine will represent what many websites will soon use - it distinguishes the current-password
from the new-password
, and makes the user confirm the new password.
<form>
<p>Username <input type="text" autocomplete="username" name="username"></p>
<p>Current Password <input type="password" autocomplete="current-password" name="current-password"></p>
<p>New Password <input type="password" autocomplete="new-password" name="new-password"></p>
<p>Confirm New Password <input type="password" autocomplete="new-password" name="confirm-new-password"></p>
</form>
I much prefer if answers reference a documentation opposed to observations about how current browsers or extensions behave.
Just use autocomplete="new-password" at the confirmation input. And if you choose to generate a new password in the password input, the confirmation input gets filled with the same value instantly. Tested in chrome.
Reference: