Selaa lähdekoodia

make password template explicit

pull/2/head
Guillaume Vincent 9 vuotta sitten
vanhempi
commit
2dc3afd628
2 muutettua tiedostoa jossa 32 lisäystä ja 9 poistoa
  1. +13
    -2
      app/lesspass.js
  2. +19
    -7
      tests/lesspass.tests.js

+ 13
- 2
app/lesspass.js Näytä tiedosto

@@ -22,8 +22,19 @@ export class lesspass {
return charCodes;
}
static _getTemplate(passwordType = 'Cvccvns') {
return passwordType.replace('l', 'vc').replace('u', 'VC');
static _getTemplate(passwordTypes = ['strong']) {
var passwordTypesInfo = {
lowercase: {value: 'vc', order: 1},
uppercase: {value: 'VC', order: 2},
number: {value: 'n', order: 3},
symbols: {value: 's', order: 4},
strong: {value: 'Cvcvns', order: 5}
};
return passwordTypes
.map(passwordType => passwordTypesInfo[passwordType])
.sort((pt1, pt2) => pt1.order > pt2.order)
.map(passwordType => passwordType.value)
.join('');
}
static _getCharType(template, index) {


+ 19
- 7
tests/lesspass.tests.js Näytä tiedosto

@@ -8,10 +8,10 @@ describe('lesspass', ()=> {
var site_information = {
'site_name': 'facebook',
'password_length': 12,
'password_type': 'luns',
'password_type': ['strong'],
'counter': 1
};
assert.equal('iwIQ8[acYT4&', lesspass.create_password(master_password, site_information));
assert.equal('Vexu8[Syce4&', lesspass.create_password(master_password, site_information));
});
});
describe('hash', ()=> {
@@ -48,12 +48,24 @@ describe('lesspass', ()=> {
});
});
describe('password templates', ()=> {
it('should get default template from password type', ()=> {
assert.equal('Cvcvns', lesspass._getTemplate());
});
it('should get template from password type', ()=> {
assert.equal('vc', lesspass._getTemplate('l'));
assert.equal('VC', lesspass._getTemplate('u'));
assert.equal('vcn', lesspass._getTemplate('ln'));
assert.equal('ns', lesspass._getTemplate('ns'));
assert.equal('Cvccvns', lesspass._getTemplate());
assert.equal('vc', lesspass._getTemplate(['lowercase']));
assert.equal('VC', lesspass._getTemplate(['uppercase']));
assert.equal('n', lesspass._getTemplate(['number']));
assert.equal('s', lesspass._getTemplate(['symbols']));
});
it('should concatenate template if two password types', ()=> {
assert.equal('vcVC', lesspass._getTemplate(['lowercase', 'uppercase']));
assert.equal('vcns', lesspass._getTemplate(['lowercase', 'number', 'symbols']));
});
it('should not care about order of type in password types', ()=> {
assert.equal(
lesspass._getTemplate(['uppercase', 'lowercase']),
lesspass._getTemplate(['lowercase', 'uppercase'])
);
});
it('should return char inside template based on modulo of the index', function () {
var template = 'cv';


Ladataan…
Peruuta
Tallenna