Skip to content

Commit 62a4047

Browse files
- Fixed a bug whereby spaces were not being treated as special characters - Implemented a regression test to assert that all special characters are being recognized as such.
1 parent b8def07 commit 62a4047

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

owasp-password-strength-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696

9797
// require at least one special character
9898
function(password) {
99-
if (!/[^A-Za-z0-9 ]/.test(password)) {
99+
if (!/[^A-Za-z0-9]/.test(password)) {
100100
return 'The password must contain at least one special character.';
101101
}
102102
},

test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,24 @@ describe('passwords', function() {
7979
result.failedTests.should.containEql(6);
8080
});
8181

82+
it('the appropriate characters should be recognized as special', function() {
83+
84+
// see: https://www.owasp.org/index.php/Password_special_characters
85+
var specials = ' !"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'.split('');
86+
87+
// test each special character
88+
specials.forEach(function(special) {
89+
var password = ['L0veSex', special, 'SecretGod'].join('');
90+
var result = owasp.test(password);
91+
result.strong.should.be.true;
92+
result.errors.should.be.empty;
93+
result.requiredTestErrors.should.be.empty;
94+
result.optionalTestErrors.should.be.empty;
95+
result.failedTests.should.be.empty;
96+
result.passedTests.should.eql([0, 1, 2, 3, 4, 5, 6]);
97+
});
98+
});
99+
82100
});
83101
});
84102

0 commit comments

Comments
 (0)