【问题标题】:autocomplete=new-password and making them confirm it via entering the password againautocomplete=new-password 并让他们通过再次输入密码来确认
【发布时间】:2018-10-15 14:35:45
【问题描述】:

html5 现在为autocomplete 属性添加了一些新属性值,以在自动填充表单时帮助用户代理。其中一个新值new-password 用于告诉用户代理输入一个 密码,而不是用户的当前 密码。

但我不清楚的是,当您的表单让用户输入两次新密码作为确认时,如何正确地告诉它为两个字段生成相同的密码?也许通过使用两个输入都使用相同的自定义 section-* 前缀,例如 autocomplete="new-password section-my-new-pw"?规范提到section-* 前缀会影响autofill scope,但它并没有过于具体地说明这对我的情况意味着什么。

这是一个示例表单,我想它将代表许多网站将很快使用的内容 - 它区分 current-passwordnew-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>

我更喜欢答案参考文档而不是观察当前浏览器或扩展程序的行为。

【问题讨论】:

  • 你不应该在段落中使用输入。
  • @undefined 为什么不呢?多年来,我在许多来自知名来源的例子中都看到了这种做法。即whatwg.orgmozilla
  • 我相信它已经过时了。段落通常用于文本,将它们用作容器可能会导致排版样式出现问题,尤其是间距。 &lt;div&gt; 通常更适合容器。

标签: html autocomplete passwords autofill change-password


【解决方案1】:

只需在确认输入时使用 autocomplete="new-password"。如果您选择在密码输入中生成新密码,确认输入会立即填充相同的值。在 chrome 中测试。

参考:

  1. chrome advice
  2. html standard discussion

【讨论】:

  • IMO 引用的链接比这个答案更清楚。基本上你应该在 BOTH 新的和确认密码字段上使用new-password 属性。
  • 也可以在 Firefox 中使用。
  • 与 Chrome 不同,Firefox 会显示第一个 &lt;input type="password" autocomplete="new-password"&gt; 的文本,因此您可以复制密码直到 input 模糊(不再是焦点)。
猜你喜欢
  • 2015-06-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-02
  • 1970-01-01
  • 2022-12-15
  • 2018-06-17
  • 2019-12-09
相关资源
最近更新 更多