Selaa lähdekoodia

add getSetOfCharacters v2 method

pull/342/head
Guillaume Vincent 8 vuotta sitten
vanhempi
commit
076d74f7d8
3 muutettua tiedostoa jossa 75 lisäystä ja 1 poistoa
  1. +2
    -1
      index.js
  2. +21
    -0
      src/v2.js
  3. +52
    -0
      tests/v2/setOfCharacters.tests.js

+ 2
- 1
index.js Näytä tiedosto

@@ -14,7 +14,8 @@ module.exports = {
_getCharType: _getCharType,
_getPasswordChar: _getPasswordChar,
_createHmac: _createHmac,
_calcEntropy: v2.calcEntropy
_calcEntropy: v2.calcEntropy,
_getSetOfCharacters: v2.getSetOfCharacters,
};

function _encryptLogin(login, masterPassword, options) {


+ 21
- 0
src/v2.js Näytä tiedosto

@@ -15,4 +15,25 @@ exports.calcEntropy = function (site, login, masterPassword, passwordProfile) {
}
});
})
};

exports.getSetOfCharacters = function (passwordProfile) {
var subsetOfCharacters = {
lowercase: 'abcdefghijklmnopqrstuvwxyz',
uppercase: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
digits: '0123456789',
symbols: '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
};

if (typeof passwordProfile === 'undefined') {
return subsetOfCharacters.lowercase + subsetOfCharacters.uppercase + subsetOfCharacters.digits;
}

var setOfCharacters = '';
['lowercase', 'uppercase', 'digits', 'symbols'].forEach(function (subset) {
if (passwordProfile.hasOwnProperty(subset) && passwordProfile[subset]) {
setOfCharacters += subsetOfCharacters[subset]
}
});
return setOfCharacters;
};

+ 52
- 0
tests/v2/setOfCharacters.tests.js Näytä tiedosto

@@ -0,0 +1,52 @@
var assert = chai.assert;

describe('LessPass', function () {
describe('set of characters', function () {
it('get default set of characters', function () {
var setOfCharacters = LessPass._getSetOfCharacters();
assert.equal('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', setOfCharacters);
assert.equal(26 * 2 + 10, setOfCharacters.length);
});
it('get default set of characters with object', function () {
var setOfCharacters = LessPass._getSetOfCharacters({
lowercase: true,
uppercase: true,
digits: true,
symbols: false
});
assert.equal('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', setOfCharacters);
assert.equal(26 * 2 + 10, setOfCharacters.length);
});
it('get set of characters only lowercase', function () {
var setOfCharacters = LessPass._getSetOfCharacters({lowercase: true});
assert.equal('abcdefghijklmnopqrstuvwxyz', setOfCharacters);
assert.equal(26, setOfCharacters.length);
});
it('get set of characters only uppercase', function () {
var setOfCharacters = LessPass._getSetOfCharacters({uppercase: true});
assert.equal('ABCDEFGHIJKLMNOPQRSTUVWXYZ', setOfCharacters);
assert.equal(26, setOfCharacters.length);
});
it('get set of characters only digits', function () {
var setOfCharacters = LessPass._getSetOfCharacters({digits: true});
assert.equal('0123456789', setOfCharacters);
assert.equal(10, setOfCharacters.length);
});
it('get set of characters only symbols', function () {
var setOfCharacters = LessPass._getSetOfCharacters({symbols: true});
assert.equal('!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~', setOfCharacters);
assert.equal(32, setOfCharacters.length);
});
it('get set of characters concat two subsets', function () {
var setOfCharacters = LessPass._getSetOfCharacters({lowercase: true, uppercase: true});
assert.equal('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', setOfCharacters);
assert.equal(26 * 2, setOfCharacters.length);
});
it('get set of characters doesn\'t care of key order in options', function () {
assert.equal(
LessPass._getSetOfCharacters({digits: true, symbols: true}),
LessPass._getSetOfCharacters({symbols: true, digits: true})
);
});
});
});

Ladataan…
Peruuta
Tallenna