Skip to content

Commit

Permalink
feat: don't allow Secret Key as password
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranjamie committed Jan 9, 2021
1 parent 315e469 commit 9aab94b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/crypto/validate-password.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { validateMnemonic } from 'bip39';
import zxcvbn, { ZXCVBNResult, ZXCVBNScore } from 'zxcvbn';

const truncateCpuDemandingPassword = (input: string) => input.substr(0, 100);
Expand All @@ -18,17 +19,21 @@ export interface ValidatedPassword extends ZXCVBNResult {
meetsLengthRequirement: boolean;
meetsScoreRequirement: boolean;
meetsAllStrengthRequirements: boolean;
isMnemonicPhrase: boolean;
}

export function validatePassword(input: string): ValidatedPassword {
const isMnemonicPhrase = validateMnemonic(input);
const password = input.length > 100 ? truncateCpuDemandingPassword(input) : input;
const result = zxcvbn(password);
const meetsScoreRequirement = hasHighestPasswordScore(result.score);
const meetsLengthRequirement = hasSufficientLength(input);
const meetsAllStrengthRequirements = meetsScoreRequirement && meetsLengthRequirement;
const meetsAllStrengthRequirements =
meetsScoreRequirement && meetsLengthRequirement && !isMnemonicPhrase;

return Object.freeze({
...result,
isMnemonicPhrase,
meetsScoreRequirement,
meetsLengthRequirement,
meetsAllStrengthRequirements,
Expand Down
4 changes: 4 additions & 0 deletions app/pages/onboarding/07-set-password/set-password.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import {
} from '@crypto/validate-password';

const weakPasswordWarningMessage = (result: ValidatedPassword) => {
if (result.isMnemonicPhrase) {
return `Don't use your mnemonic Secret Key as your wallet password. This password is used to encrypt your Secret Key.`;
}
if (result.feedback.suggestions.length > 0) {
return `${result.feedback.suggestions.join(' ')}`;
}
Expand Down Expand Up @@ -48,6 +51,7 @@ export const SetPassword: React.FC = () => {
const pass = e.currentTarget.value;
setPassword(pass);
const result = validatePassword(pass);
if (result.isMnemonicPhrase) setHasSubmitted(true);
setStrengthResult(result);
};

Expand Down

0 comments on commit 9aab94b

Please sign in to comment.