我使用了 autocomplete="false" ("/nope/no /new-password")。
在 formControl 和 FromGroup 中,我什至尝试通过使用本机元素并将属性设置为 false 来使用指令。
但是,我仍然没有禁用自动完成/自动填充的解决方案。
是否可以使用我们的脚本更改浏览器级别设置以关闭自动建议/自动填充?
我已经尝试了很多,但我做不到。在这里,我附上了使用表单级别和指令级别的代码。
<form [formGroup]="loginForm" autocomplete="off">
<input matInput placeholder="Username" formControlName="username" autocomplete="off">
<input matInput type="password" formControlName="password" autocomplete="new-password">
</form>
import { Directive, ElementRef } from '@angular/core';
@Directive({
selector: '[autocompleteOff]'
})
export class AutocompleteOffDirective {
constructor(private _el: ElementRef) {
let w: any = window;
let isChrome = w.chrome;
if (isChrome) {
this._el.nativeElement.setAttribute('autocomplete', 'off');
this._el.nativeElement.setAttribute('autocorrect', 'off');
this._el.nativeElement.setAttribute('autocapitalize', 'none');
this._el.nativeElement.setAttribute('spellcheck', 'false');
}
}
}
恐怕现代浏览器开发人员强烈认为密码管理器是最安全的策略,因此您无法禁用它们来输入
type=password
。您可能应该遵循世界其他地方并允许用户使用密码管理器,但如果您是某种不墨守成规的反叛者,您可以制作自己的“隐藏”字体并使用 type=text
就像这样答案:
https://stackoverflow.com/a/22457652/12914833
来自 Mozilla 文档:
即使没有主密码,浏览器内密码管理通常也被视为安全的净收益。由于用户不必记住浏览器为他们存储的密码,因此他们可以选择比其他方式更强的密码。
因此,许多现代浏览器不支持登录字段的 autocomplete="off" :
如果网站为表单设置了 autocomplete="off",并且该表单包含用户名和密码输入字段,则浏览器仍会记住此登录,如果用户同意,浏览器将在下次登录时自动填充这些字段。用户访问该页面。
如果网站为用户名和密码输入字段设置 autocomplete="off",则浏览器仍会记住此登录,如果用户同意,浏览器将在用户下次访问该页面时自动填充这些字段。
这是 Firefox(自版本 38 起)、Google Chrome(自版本 34 起)和 Internet Explorer(自版本 11 起)中的行为。
实际上,用户只需下载扩展即可解决问题
autocomplete=off
,因此您不会通过设置来提供任何安全值。这实际上是用户决定是否自动填写他们的凭据。
确实很难完全关闭,但可以使用
off webauthn
强制其停用,例如:
<input matInput type="password" formControlName="pwd" autocomplete="off webauthn">