From 6cd97da3d39acbae3e8e3937abc1db2f83a0e7ea Mon Sep 17 00:00:00 2001 From: Valentine Zavgorodnev <i@valzav.com> Date: Wed, 19 Oct 2016 13:00:09 -0400 Subject: [PATCH] Warn if password does not match checksum. #479 (#503) --- app/components/elements/Template.jsx | 1 + app/components/modules/LoginForm.jsx | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/components/elements/Template.jsx b/app/components/elements/Template.jsx index 7b341d143..52132f3e4 100644 --- a/app/components/elements/Template.jsx +++ b/app/components/elements/Template.jsx @@ -31,6 +31,7 @@ class Template extends React.Component { // } // componentWillUpdate(nextProps, nextState) { + // // Can't call this.setState() here, use componentWillReceiveProps instead // } // componentDidUpdate(prevProps, prevState) { diff --git a/app/components/modules/LoginForm.jsx b/app/components/modules/LoginForm.jsx index 0ec72d184..9c5fb2ace 100644 --- a/app/components/modules/LoginForm.jsx +++ b/app/components/modules/LoginForm.jsx @@ -1,7 +1,7 @@ /* eslint react/prop-types: 0 */ import React, { PropTypes, Component } from 'react'; import ReactDOM from 'react-dom'; -import {PublicKey} from 'shared/ecc' +import {PublicKey, PrivateKey} from 'shared/ecc' import transaction from 'app/redux/Transaction' import g from 'app/redux/GlobalReducer' import user from 'app/redux/User' @@ -155,6 +155,11 @@ class LoginForm extends Component { </div>; } } + const standardPassword = checkPasswordChecksum(password.value) + const password_info = standardPassword === undefined ? null : + standardPassword ? 'Password checks out and appears valid.' : + 'This password was probably typed or copied incorrectly.' + const form = ( <form onSubmit={handleSubmit(data => { // bind redux-form to react-redux @@ -173,6 +178,7 @@ class LoginForm extends Component { <div> <input type="password" required ref="pw" placeholder="Password or WIF" {...password.props} autoComplete="on" disabled={submitting} /> <div className="error">{error} </div> + {password_info && <div className="warning">{password_info} </div>} </div> {loginBroadcastOperation && <div> <div className="info">This operation requires your {authType} key (or use your master password).</div> @@ -219,6 +225,15 @@ function urlAccountName() { return suggestedAccountName } +function checkPasswordChecksum(password) { + if(!/^P.{45,}/.test(password)) {// 52 is the length + // not even close + return undefined + } + const wif = password.substring(1) + return PrivateKey.isWif(wif) +} + import {connect} from 'react-redux' export default connect( -- GitLab