Преглед изворни кода

encrypt text with master password

pull/1/head
Guillaume Vincent пре 9 година
родитељ
комит
c3d9c6df65
2 измењених фајлова са 22 додато и 13 уклоњено
  1. +7
    -2
      app/password-generator.js
  2. +15
    -11
      tests/password-generator.tests.js

+ 7
- 2
app/password-generator.js Прегледај датотеку

@@ -1,9 +1,14 @@
(function () {
'use strict';

var crypto = require('crypto');

class PasswordGenerator {
make_password(key, salt){
return "azertyuiop";
static make_password(key, text, length = 10) {
var password = crypto.createHmac('sha1', key).update(text).digest('hex');
return new Buffer(password).toString('base64').substring(0, length);
}
}

module.exports = PasswordGenerator;
}());

+ 15
- 11
tests/password-generator.tests.js Прегледај датотеку

@@ -1,16 +1,20 @@
(function () {
'use strict';
'use strict';

var assert = require('assert');
var PasswordGenerator = require('../app/password-generator');
var assert = require('assert');
var PasswordGenerator = require('../app/password-generator');

describe('password-generator',function () {
it('should return a default password with a size of 10',function () {
var passwordGenerator = new PasswordGenerator();

var generatedPassword = passwordGenerator.make_password('password', 'facebook');

assert.equal(10, generatedPassword.length);
describe('password-generator', function () {
it('should return a default password with a size of 10', function () {
var generatedPassword = PasswordGenerator.make_password('password', 'facebook');
assert.equal(10, generatedPassword.length);
});
it('should allow to change password length', function () {
var generatedPassword = PasswordGenerator.make_password('password', 'facebook', 12);
assert.equal(12, generatedPassword.length);
});
it('should hmac text with master password', function () {
assert.equal('MjE5Y2I1OG', PasswordGenerator.make_password('password', 'facebook'));
});
});
});
}());

Loading…
Откажи
Сачувај