Sfoglia il codice sorgente

Improve LessPass generatePassword API

pull/531/head
Guillaume Vincent 4 anni fa
parent
commit
bf0552d4ea
3 ha cambiato i file con 43 aggiunte e 8 eliminazioni
  1. +23
    -7
      packages/lesspass/index.js
  2. +1
    -1
      packages/lesspass/package.json
  3. +19
    -0
      packages/lesspass/test.js

+ 23
- 7
packages/lesspass/index.js Vedi File

@@ -2,23 +2,39 @@ const LessPassFingerprint = require("lesspass-fingerprint");
const LessPassEntropy = require("lesspass-entropy");
const LessPassRenderPassword = require("lesspass-render-password");

function generatePassword(site, login, masterPassword, passwordProfile) {
function generatePassword(p1, p2, p3, p4) {
const isAPIv10 = p3 === undefined;
if (!isAPIv10) {
console.warn(
"LessPass generatePassword API changed. Please update your code. Old API will be removed on version 10."
);
}
const site = isAPIv10 ? p1.site : p1;
const login = isAPIv10 ? p1.login : p2;
const masterPassword = isAPIv10 ? p2 : p3;
const length = isAPIv10 ? p1.length : p4.length;
const counter = isAPIv10 ? p1.counter : p4.counter;
const lowercase = isAPIv10 ? p1.lowercase : p4.lowercase;
const uppercase = isAPIv10 ? p1.uppercase : p4.uppercase;
const digits = isAPIv10 ? p1.digits : p4.numbers;
const symbols = isAPIv10 ? p1.symbols : p4.symbols;

return LessPassEntropy.calcEntropy(
{
site,
login,
options: {
counter: passwordProfile.counter
counter
}
},
masterPassword
).then(entropy => {
const options = {
length: passwordProfile.length,
lowercase: passwordProfile.lowercase,
uppercase: passwordProfile.uppercase,
digits: passwordProfile.numbers,
symbols: passwordProfile.symbols
length,
lowercase,
uppercase,
digits,
symbols
};
const generatedPassword = LessPassRenderPassword.renderPassword(
entropy,


+ 1
- 1
packages/lesspass/package.json Vedi File

@@ -1,6 +1,6 @@
{
"name": "lesspass",
"version": "9.1.9",
"version": "9.2.0",
"description": "LessPass core module",
"license": "GPL-3.0",
"author": "Guillaume Vincent <guillaume@oslab.fr>",


+ 19
- 0
packages/lesspass/test.js Vedi File

@@ -38,3 +38,22 @@ test("createFingerprint", () => {
]);
});
});

test("generatePassword simpler API", () => {
const passwordProfile = {
site: "example.org",
login: "contact@example.org",
lowercase: true,
uppercase: true,
digits: true,
symbols: true,
length: 16,
counter: 1,
version: 2
};
LessPass.generatePassword(passwordProfile, "password").then(
passwordGenerated => {
expect(passwordGenerated).toBe("WHLpUL)e00[iHR+w");
}
);
});

Caricamento…
Annulla
Salva