autocomplete=new-password and making them confirm it via entering the password again
Asked Answered
S

2

42

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.

Siegler answered 5/5, 2018 at 5:56 Comment(4)
You should not be using inputs inside paragraphs.Amii
@Amii Why not? I've seen this practice in many examples from reputable sources for many years. i.e. whatwg.org and mozillaSiegler
I believe it's outdated. Paragraphs are usually meant for text and using them as containers could cause issues with typography styling, especially spacing. <div> is usually much better for containers.Amii
Inputs in <p> are fine in comparison to unlabeled inputs. The example should be using <label> elementsHopefully
S
56

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:

  1. chrome advice
  2. html standard discussion
Saccule answered 7/9, 2018 at 9:56 Comment(5)
IMO the referenced links are more clear than this answer. Basically you should use the new-password attribute on BOTH new and confirm password fields.Iyar
Works in Firefox too.Doerr
As opposed to Chrome, Firefox will make the first <input type="password" autocomplete="new-password">'s text visible, so you can copy the password until the input is blurred (no longer in focus).Vitta
@Vitta lol, after almost 10 years in web dev your comment make me realize why it is called "blur". As in blurred image vs focused image ...Worry
@Worry Yeah, it's a clever metaphor, albeit, not a very clear one :)Doubleedged
P
-2

Mostly autocomplete="new-password" works, but if still it does not, try using autocomplete="one-time-code". It worked for me.

<input type="text" name="name" id="name" placeholder="Your Name*" 
    required autocomplete="one-time-code">

Or

$('#banner-form input').attr('autocomplete', 'one-time-code');
Psilomelane answered 6/5, 2024 at 14:37 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.