0

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');
    }
  }
}
Muhammet Can TONBUL
  • 3,217
  • 3
  • 25
  • 37

1 Answers1

0

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.

Chris Hamilton
  • 9,252
  • 1
  • 9
  • 26