瀏覽代碼

simplify password template

pull/2/head
Guillaume Vincent 9 年之前
父節點
當前提交
193f0e2449
共有 2 個檔案被更改,包括 12 行新增35 行删除
  1. +3
    -22
      app/lesspass.js
  2. +9
    -13
      tests/lesspass.tests.js

+ 3
- 22
app/lesspass.js 查看文件

@@ -1,6 +1,5 @@
import crypto from 'crypto';
export class lesspass {
static create_password(master_password, site_information) {
var hash = this._create_hash(master_password, site_information);
@@ -8,8 +7,7 @@ export class lesspass {
return this._encode(hash, template);
}
static _create_hash(master_password, {site_name, password_length=10, counter= 1}) {
static _create_hash(master_password, {site_name, password_length=12, counter=1}) {
var salt = site_name + counter.toString();
var password = crypto.createHmac('sha256', master_password).update(salt).digest('hex');
return password.substring(0, password_length);
@@ -24,25 +22,8 @@ export class lesspass {
return charCodes;
}
static _getTemplate(passwordType) {
var templates = {
l: "cv",
u: "CV",
n: "n",
s: "s",
lu: "a",
ln: "cvn",
ls: "cvs",
un: "CVn",
us: "CVs",
ns: "ns",
lun: "an",
uns: "CVns",
lns: "cvns",//alphanumeric lowercase
lus: "as",
luns: "cvCVns"//all, strong
};
return templates[passwordType];
static _getTemplate(passwordType = 'Cvccvns') {
return passwordType.replace('l', 'vc').replace('u', 'VC');
}
static _getCharType(template, index) {


+ 9
- 13
tests/lesspass.tests.js 查看文件

@@ -11,22 +11,22 @@ describe('lesspass', ()=> {
'password_type': 'luns',
'counter': 1
};
assert.equal('veXU8[syCE4&', lesspass.create_password(master_password, site_information));
assert.equal('iwIQ8[acYT4&', lesspass.create_password(master_password, site_information));
});
});
describe('hash', ()=> {
it('should have default length of 10', ()=> {
it('should have default length of 12', ()=> {
var master_password = "password";
var site_information = {'site_name': 'facebook'};
assert.equal(10, lesspass._create_hash(master_password, site_information).length);
assert.equal(12, lesspass._create_hash(master_password, site_information).length);
});
it('should be able to create hash with defined length', ()=> {
var master_password = "password";
var site_information = {
'site_name': 'facebook',
'password_length': 12
'password_length': 10
};
assert.equal(12, lesspass._create_hash(master_password, site_information).length);
assert.equal(10, lesspass._create_hash(master_password, site_information).length);
});
it('should return two different password if site different', ()=> {
var master_password = "password";
@@ -49,15 +49,11 @@ describe('lesspass', ()=> {
});
describe('password templates', ()=> {
it('should get template from password type', ()=> {
assert.equal('cv', lesspass._getTemplate('l'));
assert.equal('CV', lesspass._getTemplate('u'));
assert.equal('cvn', lesspass._getTemplate('ln'));
assert.equal('vc', lesspass._getTemplate('l'));
assert.equal('VC', lesspass._getTemplate('u'));
assert.equal('vcn', lesspass._getTemplate('ln'));
assert.equal('ns', lesspass._getTemplate('ns'));
});
xit('should get template from alias', ()=> {
assert.equal(lesspass._getTemplate('luns'), lesspass._getTemplate('strong'));
assert.equal(lesspass._getTemplate('an'), lesspass._getTemplate('alphanumeric'));
assert.equal(lesspass._getTemplate('n'), lesspass._getTemplate('numeric'));
assert.equal('Cvccvns', lesspass._getTemplate());
});
it('should return char inside template based on modulo of the index', function () {
var template = 'cv';


Loading…
取消
儲存