Problem/Motivation
This used to be called complexity, but was renamed in #2464895: Rename "complexity" constraint. Based on #2662370: Ensure password policy meets ISM guidelines, we'll need this constraint type. This is a little different from the "character type" constraint, because it requires a minimum number of characters from N character sets vs N characters from a specific character set.
Proposed resolution
Write and merge this constraint type.
Remaining tasks
Create a patch.
User interface changes
A new constraint type.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #27 | password_policy-character_types-2667486-27.patch | 1.16 KB | nerdstein |
| #25 | interdiff.txt | 2.79 KB | sam152 |
| #25 | 2667486-character-types-constraint-25.patch | 10.2 KB | sam152 |
| #22 | interdiff.txt | 1.55 KB | aohrvetpv |
| #22 | 2667486-character-types-constraint-22.patch | 7.4 KB | aohrvetpv |
Comments
Comment #2
sam152 commentedComment #3
sam152 commentedHere is an initial implementation based on the same business rules as the D7 version. Feedback welcome.
Comment #4
sam152 commentedRemoved some unused left over code.
Comment #5
sam152 commentedRemoved the wrong bit of debug code.
Comment #6
benjy commentedThe $password needs wrapping in preg_quote otherwise special chars in the password will break this? We should also add a test for this.
So, they only need to have 1 of these characters? Having two of them doesn't help?
@types doesn't have a replacement.
Comment #7
aohrvetpv commentedISM?
Comment #8
benjy commentedhttp://www.asd.gov.au/infosec/ism/
Comment #9
aohrvetpv commentedThanks, benjy.
Re patch in #5: It'd probably be clearer to use named character classes (e.g.,
[:punct:]):https://secure.php.net/manual/en/regexp.reference.character-classes.php
When I read
strpbrk($password, '\'#$%!^&*()+=-[]\;,./{}|":<>?~'), I wonder if that list is the complete list of special characters.Comment #10
aohrvetpv commentedThat's how the constraint works in 7.x-1.x. The idea is to ensure the password is drawn from a large set of possible characters. If a password has only special characters, it might be easier to crack than a password that has numbers, letters, and special characters.
The constraint checks the number of character types, not the number of characters of each type.
Comment #11
sam152 commentedThe variable is the subject string.
Correct.
Done.
I'd say the guts are covered by the unit test, so I'll add this as a dependency on one of the other integration tests for the schema validation. It looks like this is already the case for one of the other modules.
Good point, made this a little more resilient.
Personally I didn't even know about this, and would probably be confused reading it. The ranges seem to be pretty clear with what they cover, and :alpha: seems more vague. Is it just lowercase, uppercase or both?
Comment #12
sam152 commentedIs there a reason automated testing is disabled? Not sure what the status of HEAD is.
Comment #13
aohrvetpv commentedI think the 8.x-3.x tests aren't working currently:
#2635986: Make tests pass
Comment #14
sam152 commentedAh okay. Will this block new contributions such as this?
Comment #15
aohrvetpv commentedChanges:
- Tweaked .info.yml description to avoid confusion with "Character Type" constraint.
- Corrected @file comment.
- Marked invalid class comment with "FIXME".
- Added comma after last multi-line array item per coding standards.
- Changed a validation message that seemed incorrect.
- Changed function short descriptions to third-person singular per documentation standards.
- Changed wording of test class comment.
Comments:
- The "Character Type" and "Character Types" constraint names are confusingly similar. The names seem to imply a singular/plural relationship, but they do not have that relationship. I think we ought to make the names more distinct. Any ideas? Maybe "Characters of Type" instead of "Character Type"? To me it seems like "Character Type" isn't really a constraint on the character type; it's a constraint on the number of characters of a type. "Character Types" though is a constraint on the number of character types.
- "Character types" and "character sets" are used interchangeably. It would seem to me better to pick one, unless there is some advantage to using different terms in different contexts.
- Would it be better to validate 2 to 4 rather than 1 to 4? Seems pointless to set the value to 1.
Comment #16
aohrvetpv commentedIf I say yes, will you fix the tests? :)
nerdstein has been making the 8.x-3.x commits, so I defer to him.
Comment #17
sam152 commentedComment #18
aohrvetpv commentedpassword_policyandpassword_policy_lengthhave test code insrc/Tests, butpassword_policy_character_typeshas it intests/src. Is the latter more proper? Or should we change the location tosrc/Testsfor consistency?Comment #19
sam152 commentedI believe "tests/src" is required for unit tests and "src/Tests" is for web tests. These locations can't be changed.
Comment #20
aohrvetpv commented- Removed extra blank line per Coder.
- Corrected class comment.
- Added visibility declaration to
validate(). (Absent from existing constraints, but against coding standards.)- Changed minimum character types to 2.
- Re-ordered conditional for consistency with ordering of same conditions later in code.
- Changed "character sets" to "character types".
- "Select the number of character ..." -> "Select the minimum number of character ..."
- Added word "four" so administrator maybe does not need to count character types.
- Added file comment per Coder.
- Added blank line between last method closing brace and class closing brace per Coder.
Comment #21
aohrvetpv commentedAh, OK. That makes sense.
I think the unit test is great--short and sweet--but the existing constraints all have web tests. Perhaps we should add those for consistency. There is no testing of setting the configuration for this constraint, though the existing constraints all have "Operations" web tests that test constraint configuration.
Comment #22
aohrvetpv commented- Fixed invalid
preg_match()pattern. (The unit test would have caught.)- Removed test input that causes failure with change to minimum constraint value of 2.
Comment #23
aohrvetpv commentedWhy is it necessary to stub
t()? (Why it is necessary to specify't'in the array passed tosetMethods()?)I can see that the tests don't run properly if it is not used, but am having trouble understanding why.
Comment #24
sam152 commentedPerhaps a web test would be good but if the abstraction is tested already, it's a pretty simple form.
I believe t is mocked so that calls aren't made out to the actual translation system, which would break the unit test.
Comment #25
sam152 commentedI've added the web test that tests the configuration form as requested. While doing this, I found "validateConfigurationForm" wasn't being called. I've added this as well.
Comment #26
nerdsteinSorry for being behind on this. I'm getting caught up on this thread and will post updates as soon as possible.
Comment #27
nerdsteinThe info file was updated in a previous issue, as such the patch needed rebuilt.
And, some feedback...
error_message = @Translation("Your password needs to be more complex.")This is quite ambiguous. It should be more relevant. My new patch updates this.
'#title' => $this->t('Number of character types'),This should note minimum, not just number. My patch updates this.
'#type' => 'number',This accepts any number when we only have a fixed number of character types. This needs to be a select list from 1-4. Patch will have this.
I have tested all of this and it should be good.
Comment #28
nerdsteinMerged to 8.x-3.x
Comment #29
nerdsteinI turned on testing, by the way
Comment #30
nerdsteinMy original patch was bad (please disregard), but I got all of the code up to 8.x-3.x and credited to Sam152.
One minor issue I found was the config schema was named "password_length" and not "character_types". I renamed the file in accordance with the appropriate submodule.
Comment #31
benjy commentedThe tests don't seem to be passing for 8.x-3.x
Comment #32
nerdsteinYes, that's a known issue. Care to take a stab?
Comment #33
benjy commentedNo afraid not, I've got my hands full with migrate issues.
Comment #34
nerdsteinOK, we're tracking it here:
https://www.drupal.org/node/2635986
Feel free to contribute if you wish to help this along.
Comment #38
plingamn commentedHello Nerdstein,
Hope you are doing good.
I am using LDAP module in Drupal8. I have the LDAP module setup so that when ever the password is changed in drupal, it should reflect in LDAP too. The password update is breaking in LDAP when ever I use these characters in these password --> & " ' < > . Please let me know is there anything that I can do to fix the issue.
--
Thank you
Prashanth