зеркало из
1
0
Форкнуть 0

feat(src): Use more granular status messages.

* Remove leading `PASSWORD_`, it's implied.
* `NOT_STRONG_ENOUGH` => `ALL_LETTERS_OR_NUMBERS`
* `SUCCESS` => `LONG_ENOUGH` if the password >= 12 characters.
* `SUCCESS` => `BLOOMFILTER_MISS` if the bloomfilter is used.
This commit is contained in:
Shane Tomlinson 2015-08-18 16:47:18 +01:00
Родитель 72827d1b48
Коммит 06951de54d
4 изменённых файлов: 34 добавлений и 32 удалений

Просмотреть файл

@ -205,12 +205,13 @@ define('passwordcheck',[
var bloom = new BloomFilter(bloomFilterData, numberOfHashes);
var MESSAGES = {
ALL_LETTERS_OR_NUMBERS: 'ALL_LETTERS_OR_NUMBERS',
BLOOMFILTER_HIT: 'BLOOMFILTER_HIT',
BLOOMFILTER_MISS: 'BLOOMFILTER_MISS',
LONG_ENOUGH: 'LONG_ENOUGH',
MISSING_PASSWORD: 'MISSING_PASSWORD',
NOT_STRONG_ENOUGH: 'NOT_STRONG_ENOUGH',
PASSWORD_NOT_A_STRING: 'PASSWORD_NOT_A_STRING',
PASSWORD_TOO_SHORT: 'PASSWORD_TOO_SHORT',
SUCCESS: 'SUCCESS'
NOT_A_STRING: 'NOT_A_STRING',
TOO_SHORT: 'TOO_SHORT'
};
function isAllLetters(password) {
@ -233,18 +234,18 @@ define('passwordcheck',[
if (! password) {
callback(MESSAGES.MISSING_PASSWORD);
} else if (typeof password !== 'string') {
callback(MESSAGES.PASSWORD_NOT_A_STRING);
callback(MESSAGES.NOT_A_STRING);
} else if (isTooShort(password)) {
callback(MESSAGES.PASSWORD_TOO_SHORT);
callback(MESSAGES.TOO_SHORT);
} else if (isLongEnough(password)) {
// password is long enough, it's automatically good.
callback(MESSAGES.SUCCESS);
callback(MESSAGES.LONG_ENOUGH);
// password is non-empty, a string and length greater
// than minimum length, shorter than the strong length.
} else if (isAllLetters(password)) {
callback(MESSAGES.NOT_STRONG_ENOUGH);
callback(MESSAGES.ALL_LETTERS_OR_NUMBERS);
} else if (isAllNumbers(password)) {
callback(MESSAGES.NOT_STRONG_ENOUGH);
callback(MESSAGES.ALL_LETTERS_OR_NUMBERS);
// Only if the password has a chance of being
// strong, but not too strong, is the bloom filter
// checked. All the above tests mean the bloomfilter
@ -252,7 +253,7 @@ define('passwordcheck',[
} else if (bloom.test(password)) {
callback(MESSAGES.BLOOMFILTER_HIT);
} else {
callback(MESSAGES.SUCCESS);
callback(MESSAGES.BLOOMFILTER_MISS);
}
};
};

2
build/fxa-password-strength-checker.min.js поставляемый

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -19,12 +19,13 @@ define([
var bloom = new BloomFilter(bloomFilterData, numberOfHashes);
var MESSAGES = {
ALL_LETTERS_OR_NUMBERS: 'ALL_LETTERS_OR_NUMBERS',
BLOOMFILTER_HIT: 'BLOOMFILTER_HIT',
BLOOMFILTER_MISS: 'BLOOMFILTER_MISS',
LONG_ENOUGH: 'LONG_ENOUGH',
MISSING_PASSWORD: 'MISSING_PASSWORD',
NOT_STRONG_ENOUGH: 'NOT_STRONG_ENOUGH',
PASSWORD_NOT_A_STRING: 'PASSWORD_NOT_A_STRING',
PASSWORD_TOO_SHORT: 'PASSWORD_TOO_SHORT',
SUCCESS: 'SUCCESS'
NOT_A_STRING: 'NOT_A_STRING',
TOO_SHORT: 'TOO_SHORT'
};
function isAllLetters(password) {
@ -47,18 +48,18 @@ define([
if (! password) {
callback(MESSAGES.MISSING_PASSWORD);
} else if (typeof password !== 'string') {
callback(MESSAGES.PASSWORD_NOT_A_STRING);
callback(MESSAGES.NOT_A_STRING);
} else if (isTooShort(password)) {
callback(MESSAGES.PASSWORD_TOO_SHORT);
callback(MESSAGES.TOO_SHORT);
} else if (isLongEnough(password)) {
// password is long enough, it's automatically good.
callback(MESSAGES.SUCCESS);
callback(MESSAGES.LONG_ENOUGH);
// password is non-empty, a string and length greater
// than minimum length, shorter than the strong length.
} else if (isAllLetters(password)) {
callback(MESSAGES.NOT_STRONG_ENOUGH);
callback(MESSAGES.ALL_LETTERS_OR_NUMBERS);
} else if (isAllNumbers(password)) {
callback(MESSAGES.NOT_STRONG_ENOUGH);
callback(MESSAGES.ALL_LETTERS_OR_NUMBERS);
// Only if the password has a chance of being
// strong, but not too strong, is the bloom filter
// checked. All the above tests mean the bloomfilter
@ -66,7 +67,7 @@ define([
} else if (bloom.test(password)) {
callback(MESSAGES.BLOOMFILTER_HIT);
} else {
callback(MESSAGES.SUCCESS);
callback(MESSAGES.BLOOMFILTER_MISS);
}
};
};

Просмотреть файл

@ -19,21 +19,21 @@ define(['chai', 'passwordcheck'], function (chai, PasswordCheck) {
});
});
it('returns PASSWORD_TOO_SHORT when password is lower than minLength', function () {
it('returns TOO_SHORT when password is lower than minLength', function () {
passwordcheck('124as', function (res) {
assert.equal('PASSWORD_TOO_SHORT', res);
assert.equal('TOO_SHORT', res);
});
});
it('returns NOT_STRONG_ENOUGH when password is all numbers', function () {
it('returns ALL_LETTERS_OR_NUMBERS when password is all numbers', function () {
passwordcheck('124567890', function (res) {
assert.equal('NOT_STRONG_ENOUGH', res);
assert.equal('ALL_LETTERS_OR_NUMBERS', res);
});
});
it('returns NOT_STRONG_ENOUGH when password is all letters', function () {
it('returns ALL_LETTERS_OR_NUMBERS when password is all letters', function () {
passwordcheck('dragondrag', function (res) {
assert.equal('NOT_STRONG_ENOUGH', res);
assert.equal('ALL_LETTERS_OR_NUMBERS', res);
});
});
@ -46,18 +46,18 @@ define(['chai', 'passwordcheck'], function (chai, PasswordCheck) {
});
});
it('returns SUCCESS when password >= 12 characters', function () {
it('returns LONG_ENOUGH when password >= 12 characters', function () {
var longPassword = 'thisis12char';
passwordcheck(longPassword, function (res) {
assert.equal('SUCCESS', res);
assert.equal('LONG_ENOUGH', res);
});
});
it('returns SUCCESS when password is not caught by any other tests', function () {
var goodPasswords = ['notinyourdictionary!', 'imaynotbetheretoo', 'thisisagoodcleanpassword', 'combo1234$#@'];
it('returns BLOOMFILTER_MISS when password is not caught by any other tests', function () {
var goodPasswords = ['notinyour!', 'combo1234$#'];
goodPasswords.forEach(function (password) {
passwordcheck(password, function (res) {
assert.equal('SUCCESS', res, password);
assert.equal('BLOOMFILTER_MISS', res, password);
});
});
});