禁用自动完成在角度下不起作用。是否可以更改浏览器设置 =>关闭=>使用 Java 脚本自动完成

发布于 2025-01-19 13:06:45 字数 1136 浏览 2 评论 0 原文

我已经使用了autoComplete =“ false”(“/nope/no/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');
    }
  }
}

I have used autocomplete="false" ("/nope/no /new-password").

In both formControl and FromGroup even I have tried using directive by using native element and setting the property as false.

But still, I do not have the solution for disabling the autocomplete/autofill.

Is it possible to change the browser level setting as turn off auto Suggestions/autofill by using our script?

I have tried a lot, but I can't. Here I have attached the code which I have using both the form level and directive level.

<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');
    }
  }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

婴鹅 2025-01-26 13:06:45

确实,很难完全关闭该产品,但是可以用 OFF WebAuthn 迫使其灭活效果,例如:

<input matInput type="password" formControlName="pwd" autocomplete="off webauthn">

来自 https://stackoverflow.com/a/a/77011536/3994745

Indeed it is difficult to completely switch off the, but it is possible to force its inactivation with off webauthn, example:

<input matInput type="password" formControlName="pwd" autocomplete="off webauthn">

From https://stackoverflow.com/a/77011536/3994745

提赋 2025-01-26 13:06:45

恐怕Modern Browser Devs非常强烈地认为密码管理器是最安全的策略,因此您无法禁用 输入 type = password 。您可能应该只符合世界其他地方并允许用户使用密码管理器,但是如果您是某种不符合形式的反叛者,则可以制作自己的“隐藏”字体,并使用 type = text = text = text 喜欢在此答案中:

https://stackoverflow.com/a/22457652/12914833

即使没有主密码,浏览器内密码管理通常也被视为安全性的净收益。由于用户不必记住浏览器存储给他们的密码,因此他们能够选择比以前更强的密码。

因此,许多现代浏览器不支持autoComplete =“ OFF”登录字段:

如果网站设置autoComplete =“ off”表格,并且该表单包含用户名和密码输入字段,则浏览器仍然提供记住此登录的信息,如果用户同意,则浏览器将在下一步中自动填充这些字段用户访问页面的时间。

如果网站设置了autocomplete =“ off”用于用户名和密码输入字段,则浏览器仍会提供记住此登录名,如果用户同意,则浏览器将在下次用户访问页面时自动填充这些字段。

这是Firefox(自版本38),Google Chrome(自34)和Internet Explorer(自版本11)中的行为。

实际上,用户可以只下载扩展程序即可使用 autoComplete = OFF ,因此您无法通过设置它提供任何安全值。这确实是用户决定是否自动填写凭证。

I'm afraid modern browser devs feel very strongly that password managers are the most secure strategy and so you cannot disable them for an input of type=password. You should probably just conform to the rest of the world and allow the user to use a password manager, but if you're some kind of non-conformist rebel you can make your own 'hidden' font and use type=text like in this answer:

https://stackoverflow.com/a/22457652/12914833

From the Mozilla docs:

https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion#the_autocomplete_attribute_and_login_fields

Even without a master password, in-browser password management is generally seen as a net gain for security. Since users do not have to remember passwords that the browser stores for them, they are able to choose stronger passwords than they would otherwise.

For this reason, many modern browsers do not support autocomplete="off" for login fields:

If a site sets autocomplete="off" for a form, and the form includes username and password input fields, then the browser still offers to remember this login, and if the user agrees, the browser will autofill those fields the next time the user visits the page.

If a site sets autocomplete="off" for username and password input fields, then the browser still offers to remember this login, and if the user agrees, the browser will autofill those fields the next time the user visits the page.

This is the behavior in Firefox (since version 38), Google Chrome (since 34), and Internet Explorer (since version 11).

Realistically, users can just download extensions to work around autocomplete=off so you're not providing any security value by setting it. It's really the user's decision to auto-fill their credentials or not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文