Pārlūkot izejas kodu

fix error in password generator with counter

pull/44/head
Guillaume Vincent pirms 8 gadiem
vecāks
revīzija
4074b22da7
2 mainītis faili ar 44 papildinājumiem un 6 dzēšanām
  1. +2
    -2
      app/lesspass.js
  2. +42
    -4
      tests/lesspass.tests.js

+ 2
- 2
app/lesspass.js Parādīt failu

@@ -22,8 +22,8 @@ export default class lesspass {
});
}
static _createHash(masterPassword, {site, password={length: 12}, counter=1}) {
var salt = site + counter.toString();
static _createHash(masterPassword, {site, password={length: 12, counter: 1}}) {
var salt = site + password.counter.toString();
var hash = crypto.createHmac('sha256', masterPassword).update(salt).digest('hex');
return hash.substring(0, password.length);
}


+ 42
- 4
tests/lesspass.tests.js Parādīt failu

@@ -27,6 +27,29 @@ describe('LessPass', ()=> {
};
assert.equal('Vexu8[Syce4&', Lesspass.createPassword(masterPassword, entry));
});
it('should create 2 passwords different if counter different', function () {
var masterPassword = "password";
var entry = {
site: 'facebook',
password: {
length: 14,
settings: ['lowercase', 'uppercase', 'numbers', 'symbols'],
counter: 1
}
};
var entry2 = {
site: 'facebook',
password: {
length: 14,
settings: ['lowercase', 'uppercase', 'numbers', 'symbols'],
counter: 2
}
};
assert.notEqual(
Lesspass.createPassword(masterPassword, entry),
Lesspass.createPassword(masterPassword, entry2)
);
});
it('should create master password with pbkdf2 (8192 iterations and sha 256)', (done)=> {
var email = 'test@lesspass.com';
var password = "password";
@@ -59,7 +82,8 @@ describe('LessPass', ()=> {
var entry = {
site: 'facebook',
password: {
length: 10
length: 10,
counter: 1
}
};
assert.equal(10, Lesspass._createHash(masterPassword, entry).length);
@@ -75,11 +99,25 @@ describe('LessPass', ()=> {
});
it('should return two different passwords if counter different', ()=> {
var masterPassword = 'password';
var old_entry = {site: 'facebook'};
var entry = {site: 'facebook', 'counter': 2};
var entry = {
site: 'facebook',
password: {
length: 14,
settings: ['lowercase', 'uppercase', 'numbers', 'symbols'],
counter: 1
}
};
var entry2 = {
site: 'facebook',
password: {
length: 14,
settings: ['lowercase', 'uppercase', 'numbers', 'symbols'],
counter: 2
}
};
assert.notEqual(
Lesspass._createHash(masterPassword, entry),
Lesspass._createHash(masterPassword, old_entry)
Lesspass._createHash(masterPassword, entry2)
);
});
});


Notiek ielāde…
Atcelt
Saglabāt