Skip to content
This repository was archived by the owner on Apr 15, 2019. It is now read-only.

Commit

Permalink
Merge pull request #1021 from LiskHQ/1018-passphrase-case-validation
Browse files Browse the repository at this point in the history
Disallow upper case letters in passphrase - Closes #1018
  • Loading branch information
slaweet authored Dec 19, 2017
2 parents 475707b + e062981 commit 27745ef
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions i18n/locales/de/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
"What's New...": "Neues...",
"When you have the signature, you only need the publicKey of the signer in order to verify that the message came from the right private/publicKey pair. Be aware, everybody knowing the signature and the publicKey can verify the message. If ever there is a dispute, everybody can take the publicKey and signature to a judge and prove that the message is coming from the specific private/publicKey pair.": "Wenn du eine Signatur hast, brauchst du nur noch den öffentlichen Schlüssel des Unterzeichners, um zu überprüfen, ob die Nachricht von dem korrekten privaten/öffentlichen Schlüssel-Paar kommt. Bedenke dass jeder, der den öffentlichen Schlüssel besitzt, die Nachricht verifizieren kann. Wenn es eine Streitigkeit geben sollte, kann jeder den öffentlichen Schlüssel und die Signatur zu einem Richter bringen und dort beweisen, dass die Nachricht von diesem speziellen privaten/öffentlichen Schlüssel-Paar kommt.",
"Window": "Fenster",
"Word \"{{invalidWord}}\" contains upper case letters. All words must be lower case": "Das Wort \"{{invalidWord}}\" enhält Großbuchstaben. Alle Wörter müssen ausschließlich Kleinbuchstaben enthalten.",
"Word \"{{invalidWord}}\" is not on the passphrase Word List.": "Das Wort \"{{invalidWord}}\" ist in der Passphrasen-Wortliste nicht vorhanden.",
"Word \"{{invalidWord}}\" is not on the passphrase Word List. Most similar word on the list is \"{{similarWord}}\"": "Das Wort \"{{invalidWord}}\" ist nicht in der Passphrasen-Wortliste. Das ähnlichste Wort in der Liste ist \"{{similarWord}}\"",
"Yes! It's safe": "Ja! Es ist sicher",
Expand Down
1 change: 1 addition & 0 deletions i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@
"What's New...": "What's New...",
"When you have the signature, you only need the publicKey of the signer in order to verify that the message came from the right private/publicKey pair. Be aware, everybody knowing the signature and the publicKey can verify the message. If ever there is a dispute, everybody can take the publicKey and signature to a judge and prove that the message is coming from the specific private/publicKey pair.": "When you have the signature, you only need the publicKey of the signer in order to verify that the message came from the right private/publicKey pair. Be aware, everybody knowing the signature and the publicKey can verify the message. If ever there is a dispute, everybody can take the publicKey and signature to a judge and prove that the message is coming from the specific private/publicKey pair.",
"Window": "Window",
"Word \"{{invalidWord}}\" contains upper case letters. All words must be lower case": "Word \"{{invalidWord}}\" contains upper case letters. All words must be lower case",
"Word \"{{invalidWord}}\" is not on the passphrase Word List.": "Word \"{{invalidWord}}\" is not on the passphrase Word List.",
"Word \"{{invalidWord}}\" is not on the passphrase Word List. Most similar word on the list is \"{{similarWord}}\"": "Word \"{{invalidWord}}\" is not on the passphrase Word List. Most similar word on the list is \"{{similarWord}}\"",
"Yes! It's safe": "Yes! It's safe",
Expand Down
6 changes: 4 additions & 2 deletions src/components/passphraseInput/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ class PassphraseInput extends React.Component {
return this.props.t('Passphrase should have 12 words, entered passphrase has {{length}}', { length: mnemonic.length });
}

const invalidWord = mnemonic.find(word => !inDictionary(word.toLowerCase()));
const invalidWord = mnemonic.find(word => !inDictionary(word));
if (invalidWord) {
if (invalidWord.length >= 2 && invalidWord.length <= 8) {
const validWord = findSimilarWord(invalidWord);
if (validWord) {
if (invalidWord.toLowerCase() !== invalidWord) {
return this.props.t('Word "{{invalidWord}}" contains upper case letters. All words must be lower case', { invalidWord });
} else if (validWord) {
return this.props.t('Word "{{invalidWord}}" is not on the passphrase Word List. Most similar word on the list is "{{similarWord}}"', { invalidWord, similarWord: findSimilarWord(invalidWord) });
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/components/passphraseInput/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ describe('PassphraseInput', () => {
expect(wrapper.props().onChange).to.have.been.calledWith(passphrase, SIMILAR_WORD_ERROR);
});

const UPPER_CASE_ERROR = 'Word "WAGON" contains upper case letters. All words must be lower case';
it(`should call props.onChange with error='${UPPER_CASE_ERROR}' if an passphrase with a typo is entered`, () => {
const passphrase = 'WAGON stock borrow episode laundry kitten salute link globe zero feed marble';
wrapper.find('input').simulate('change', { target: { value: passphrase } });
expect(wrapper.props().onChange).to.have.been.calledWith(passphrase, UPPER_CASE_ERROR);
});

const NOT_VALID_ERROR = 'Passphrase is not valid';
it(`should call props.onChange with error="${NOT_VALID_ERROR}" if an otherwise invalid passphrase is entered`, () => {
const passphrase = 'stock wagon borrow episode laundry kitten salute link globe zero feed marble';
Expand Down
2 changes: 1 addition & 1 deletion src/utils/passphrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const generatePassphrase = ({ seed }) => (new mnemonic(new Buffer(seed.jo
* @returns {bool} isValidPassphrase
*/
export const isValidPassphrase = (passphrase) => {
const normalizedValue = passphrase.replace(/ +/g, ' ').trim().toLowerCase();
const normalizedValue = passphrase.replace(/ +/g, ' ').trim();
let isValid;
try {
isValid = normalizedValue.split(' ').length >= 12 && mnemonic.isValid(normalizedValue);
Expand Down

0 comments on commit 27745ef

Please sign in to comment.