Skip to content

Commit

Permalink
修复密码强度为1时校验出错的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
蔡金锋 committed Apr 29, 2020
1 parent 6628414 commit f2778cf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "util-helpers",
"version": "3.4.0",
"version": "3.4.1",
"description": "一个基于业务场景的工具方法库",
"main": "lib/index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/isPassword.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function isPassword(value, {
let reg = null;

if (level === 1) {
reg = new RegExp(`^(?:${numRegStr}+|[${ignorecaseRegStr}]+|[${special}]+)$/`);
reg = new RegExp(`^[${numRegStr}${ignorecaseRegStr}${special}]+$`);
} else if (level === 2) {
if (ignoreCase) {
reg = new RegExp(`^(?![${ignorecaseRegStr}]+$)(?!${numRegStr}+$)(?![${special}]+$)[${ignorecaseRegStr}${numRegStr}${special}]+$`);
Expand Down
31 changes: 30 additions & 1 deletion test/validator/isPassword.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,38 @@ describe('isPassword', () => {
expect(isPassword(true)).to.be.equal(false);
expect(isPassword(123)).to.be.equal(false);
});
it('"a12345678" => true', () => {
it('1级强度 "1234787" => true', () => {
expect(isPassword('1234787', {level: 1})).to.be.equal(true);
});
it('1级强度 "a1234787" => true', () => {
expect(isPassword('a1234787', {level: 1})).to.be.equal(true);
});
it('1级强度 "ab1234787" => true', () => {
expect(isPassword('ab1234787', {level: 1})).to.be.equal(true);
});
it('1级强度 "1a234787" => true', () => {
expect(isPassword('1a234787', {level: 1})).to.be.equal(true);
});
it('1级强度 "a1_234787" => true', () => {
expect(isPassword('a1_234787', {level: 1})).to.be.equal(true);
});
it('1级强度 "abc" => true', () => {
expect(isPassword('abc', {level: 1})).to.be.equal(true);
});
it('1级强度 "*_ )" => false', () => {
expect(isPassword('*_ )', {level: 1})).to.be.equal(false);
});

it('2级强度 "a12345678" => true', () => {
expect(isPassword('a12345678')).to.be.equal(true);
});
it('2级强度 "a1_234787" => true', () => {
expect(isPassword('a1_234787')).to.be.equal(true);
});
it('2级强度 "aa_234787" => true', () => {
expect(isPassword('aa_234787')).to.be.equal(true);
});

it('3级强度 "a12345678" => false', () => {
expect(isPassword('a12345678', { level: 3 })).to.be.equal(false);
});
Expand Down

0 comments on commit f2778cf

Please sign in to comment.