问题
From my testing so far it appears that the Chrome password generator only generates passwords with uppercase letters, lowercase letters and numbers but doesn't appear to use special characters. If I am building a website that has a password policy that requires at least one special character is there a way to make chrome aware of this policy so that the password generator will generate a compliant password?
回答1:
Yes. According to the Chromium design document for password generation it takes into account HTML5 attributes:
PasswordGenerationManager takes messages from the renderer and makes an OS specific dropdown. This UI use a PasswordGenerator to create a reasonable password for this site (tries to take in account maxlength attribute, pattern attribute, etc.). If the password is accepted, it is sent back to the renderer.
I would consider using regex to validate passwords to be an anti-pattern, but at least there's a way to do what you want.
回答2:
I dug around for a while and looked into the answer given by @user10580275, but I couldn't get it to obey the pattern like @BrunoLM.
I noticed that several websites (Quickbooks, Wordpress, Tumblr) seem to follow the rules given by Chrome and it seemed almost random whether it would conform to the rules or not. I couldn't find a pattern between them.
However I did find this article by Google explaining how to use the suggested password feature, which happened to have this in it:
If a website doesn't accept a password suggested by Chrome, let us know.
This link sends you to a form where you can fill out your website address and tell them their password generation isn't conforming to the rules. I don't know how Chrome's suggested password works under the hood, but I've submitted our url to them to see if they can adjust it.
I think the best option is to submit your URL and do your own validation live to inform the user the generated password does not match the criteria you require. It seems to ignore pattern and other attributes contrary to the design document posted.
来源:https://stackoverflow.com/questions/53062991/is-there-a-way-to-tell-chrome-password-generator-the-website-password-policy