浏览代码

fix error in password generator with counter

pull/44/head
Guillaume Vincent 8 年前
父节点
当前提交
4074b22da7
共有 2 个文件被更改,包括 44 次插入6 次删除
  1. +2
    -2
      app/lesspass.js
  2. +42
    -4
      tests/lesspass.tests.js

+ 2
- 2
app/lesspass.js 查看文件

@@ -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 查看文件

@@ -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)
);
});
});


正在加载...
取消
保存