Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Remove existence & length checks on passwords & phrases #3854

Merged
merged 5 commits into from
Dec 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions js/src/modals/CreateAccount/NewAccount/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,4 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import { ERRORS } from './newAccount';

export default from './newAccount';

export {
ERRORS
};
80 changes: 32 additions & 48 deletions js/src/modals/CreateAccount/NewAccount/newAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,9 @@ import ActionAutorenew from 'material-ui/svg-icons/action/autorenew';

import { Form, Input, IdentityIcon } from '~/ui';

import styles from '../createAccount.css';

const ERRORS = {
noName: 'you need to specify a valid name for the account',
noPhrase: 'you need to specify the recovery phrase',
noKey: 'you need to provide the raw private key',
invalidKey: 'the raw key needs to be hex, 64 characters in length and contain the prefix "0x"',
invalidPassword: 'you need to specify a password >= 8 characters',
noMatchPassword: 'the supplied passwords does not match'
};
import ERRORS from '../errors';

export {
ERRORS
};
import styles from '../createAccount.css';

export default class CreateAccount extends Component {
static contextTypes = {
Expand All @@ -49,15 +38,15 @@ export default class CreateAccount extends Component {
state = {
accountName: '',
accountNameError: ERRORS.noName,
accounts: null,
isValidName: false,
isValidPass: false,
passwordHint: '',
password1: '',
password1Error: ERRORS.invalidPassword,
password1Error: null,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afaict password1Error can be removed safely.

Copy link
Contributor Author

@jacogr jacogr Dec 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% - I have kept all these in for now for circling back. The following to be logged after doing this -

DRY-up the error checks & validation across the different parts and move to a store - validation is duplicated in the different sections, I guess by organic growth and lack of a proper store (Not a critical item, but it is messy atm and can be done much better - in short, all these are to be cleaned, removed & moved)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is #3887.

password2: '',
password2Error: ERRORS.noMatchPassword,
accounts: null,
selectedAddress: '',
isValidPass: false,
isValidName: false
password2Error: null,
selectedAddress: ''
}

componentWillMount () {
Expand Down Expand Up @@ -230,60 +219,55 @@ export default class CreateAccount extends Component {
}, this.updateParent);
}

onEditPasswordHint = (event, value) => {
onEditPasswordHint = (event, passwordHint) => {
this.setState({
passwordHint: value
passwordHint
});
}

onEditAccountName = (event) => {
const value = event.target.value;
let error = null;
const accountName = event.target.value;
let accountNameError = null;

if (!value || value.trim().length < 2) {
error = ERRORS.noName;
if (!accountName || !accountName.trim().length) {
accountNameError = ERRORS.noName;
}

this.setState({
accountName: value,
accountNameError: error,
isValidName: !error
accountName,
accountNameError,
isValidName: !accountNameError
}, this.updateParent);
}

onEditPassword1 = (event) => {
const value = event.target.value;
let error1 = null;
let error2 = null;

if (!value || value.trim().length < 8) {
error1 = ERRORS.invalidPassword;
}
const password1 = event.target.value;
let password2Error = null;

if (value !== this.state.password2) {
error2 = ERRORS.noMatchPassword;
if (password1 !== this.state.password2) {
password2Error = ERRORS.noMatchPassword;
}

this.setState({
password1: value,
password1Error: error1,
password2Error: error2,
isValidPass: !error1 && !error2
password1,
password1Error: null,
password2Error,
isValidPass: !password2Error
}, this.updateParent);
}

onEditPassword2 = (event) => {
const value = event.target.value;
let error2 = null;
const password2 = event.target.value;
let password2Error = null;

if (value !== this.state.password1) {
error2 = ERRORS.noMatchPassword;
if (password2 !== this.state.password1) {
password2Error = ERRORS.noMatchPassword;
}

this.setState({
password2: value,
password2Error: error2,
isValidPass: !error2
password2,
password2Error,
isValidPass: !password2Error
}, this.updateParent);
}

Expand Down
1 change: 1 addition & 0 deletions js/src/modals/CreateAccount/NewGeth/newGeth.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default class NewGeth extends Component {
<div className={ styles.list }>There are currently no importable keys available from the Geth keystore, which are not already available on your Parity instance</div>
);
}

const checkboxes = available.map((account) => {
const label = (
<div className={ styles.selection }>
Expand Down
51 changes: 21 additions & 30 deletions js/src/modals/CreateAccount/NewImport/newImport.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@ import EditorAttachFile from 'material-ui/svg-icons/editor/attach-file';

import { Form, Input } from '~/ui';

import ERRORS from '../errors';

import styles from '../createAccount.css';

const FAKEPATH = 'C:\\fakepath\\';
const STYLE_HIDDEN = { display: 'none' };

const ERRORS = {
noName: 'you need to specify a valid name for the account',
noPassword: 'supply a valid password to confirm the transaction',
noFile: 'select a valid wallet file to import'
};

export default class NewImport extends Component {
static propTypes = {
onChange: PropTypes.func.isRequired
Expand All @@ -40,15 +36,15 @@ export default class NewImport extends Component {
state = {
accountName: '',
accountNameError: ERRORS.noName,
passwordHint: '',
isValidFile: false,
isValidPass: false,
isValidName: false,
password: '',
passwordError: ERRORS.noPassword,
passwordError: null,
passwordHint: '',
walletFile: '',
walletFileError: ERRORS.noFile,
walletJson: '',
isValidPass: false,
isValidName: false,
isValidFile: false
walletJson: ''
}

componentWillMount () {
Expand Down Expand Up @@ -143,39 +139,34 @@ export default class NewImport extends Component {
});
}

onEditPasswordHint = (event, value) => {
onEditPasswordHint = (event, passwordHint) => {
this.setState({
passwordHint: value
passwordHint
});
}

onEditAccountName = (event) => {
const value = event.target.value;
let error = null;
const accountName = event.target.value;
let accountNameError = null;

if (!value || value.trim().length < 2) {
error = ERRORS.noName;
if (!accountName || !accountName.trim().length) {
accountNameError = ERRORS.noName;
}

this.setState({
accountName: value,
accountNameError: error,
isValidName: !error
accountName,
accountNameError,
isValidName: !accountNameError
}, this.updateParent);
}

onEditPassword = (event) => {
let error = null;
const value = event.target.value;

if (!value || !value.length) {
error = ERRORS.noPassword;
}
const password = event.target.value;

this.setState({
password: value,
passwordError: error,
isValidPass: !error
password,
passwordError: null,
isValidPass: true
}, this.updateParent);
}
}
53 changes: 24 additions & 29 deletions js/src/modals/CreateAccount/RawKey/rawKey.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Form, Input } from '~/ui';

import styles from '../createAccount.css';

import { ERRORS } from '../NewAccount';
import ERRORS from '../errors';

export default class RawKey extends Component {
static contextTypes = {
Expand All @@ -32,18 +32,18 @@ export default class RawKey extends Component {
}

state = {
rawKey: '',
rawKeyError: ERRORS.noKey,
accountName: '',
accountNameError: ERRORS.noName,
isValidKey: false,
isValidName: false,
isValidPass: false,
passwordHint: '',
password1: '',
password1Error: ERRORS.invalidPassword,
password1Error: null,
password2: '',
password2Error: ERRORS.noMatchPassword,
isValidPass: false,
isValidName: false,
isValidKey: false
password2Error: null,
rawKey: '',
rawKeyError: ERRORS.noKey
}

componentWillMount () {
Expand Down Expand Up @@ -138,7 +138,7 @@ export default class RawKey extends Component {
const accountName = event.target.value;
let accountNameError = null;

if (!accountName || accountName.trim().length < 2) {
if (!accountName || !accountName.trim().length) {
accountNameError = ERRORS.noName;
}

Expand All @@ -150,38 +150,33 @@ export default class RawKey extends Component {
}

onEditPassword1 = (event) => {
const value = event.target.value;
let error1 = null;
let error2 = null;

if (!value || value.trim().length < 8) {
error1 = ERRORS.invalidPassword;
}
const password1 = event.target.value;
let password2Error = null;

if (value !== this.state.password2) {
error2 = ERRORS.noMatchPassword;
if (password1 !== this.state.password2) {
password2Error = ERRORS.noMatchPassword;
}

this.setState({
password1: value,
password1Error: error1,
password2Error: error2,
isValidPass: !error1 && !error2
password1,
password1Error: null,
password2Error,
isValidPass: !password2Error
}, this.updateParent);
}

onEditPassword2 = (event) => {
const value = event.target.value;
let error2 = null;
const password2 = event.target.value;
let password2Error = null;

if (value !== this.state.password1) {
error2 = ERRORS.noMatchPassword;
if (password2 !== this.state.password1) {
password2Error = ERRORS.noMatchPassword;
}

this.setState({
password2: value,
password2Error: error2,
isValidPass: !error2
password2,
password2Error,
isValidPass: !password2Error
}, this.updateParent);
}
}
Loading