Skip to content

port zxcvbnStrengthBar #1061

Description

@tomholub

part of #1051

We use zxcvbn to figure out how many guesses does one have to make in brute force attempt against a user chosen pass phrase. This is a way to estimate strength of pass phrase.

zxcvbn only gives us a number. We have our own code that translates that into renderable wisdom.

From https://github.com/FlowCrypt/flowcrypt-mobile-core/blob/master/source/mobile-interface/endpoints.ts

publiczxcvbnStrengthBar=async(uncheckedReq: any)=>{constr=ValidateInput.zxcvbnStrengthBar(uncheckedReq);if(r.purpose==='passphrase'){if(typeofr.guesses==='number'){// the host has a port of zxcvbn and already knows amount of guesses per passwordreturnfmtRes(PgpPwd.estimateStrength(r.guesses));}elseif(typeofr.value==='string'){// host does not have zxcvbn, let's use zxcvbn-js to estimate guessestypeFakeWindow={zxcvbn: (password: string,weakWords: string[])=>{guesses: number}};if(typeof(windowasunknownasFakeWindow).zxcvbn!=='function'){thrownewError("window.zxcvbn missing in js")}letguesses=(windowasunknownasFakeWindow).zxcvbn(r.value,PgpPwd.weakWords()).guesses;returnfmtRes(PgpPwd.estimateStrength(guesses));}else{thrownewError('Unexpected format: guesses is not a number, value is not a string');}}else{thrownewError(`Unknown purpose: ${r.purpose}`);}

which uses this implementation we need to port: https://github.com/FlowCrypt/flowcrypt-mobile-core/blob/f80d5491451b61dcf8e539932b693fb28e84217f/source/core/pgp-password.ts#L21

Test

ava.default('zxcvbnStrengthBar',asynct=>{const{ data, json }=awaitrequest('zxcvbnStrengthBar',{guesses: 88946283684265,purpose: 'passphrase'},[]);expectNoData(data);expect(json).to.deep.equal({word: {match: 'week',word: 'poor',bar: 30,color: 'darkred',pass: false},seconds: 1111829,time: '2 weeks',});t.pass();});

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions