Skip to content
Snippets Groups Projects
Commit 6cd97da3 authored by Valentine Zavgorodnev's avatar Valentine Zavgorodnev Committed by valzav
Browse files

Warn if password does not match checksum. #479 (#503)

parent 4c280845
Branches phone
No related tags found
No related merge requests found
......@@ -31,6 +31,7 @@ class Template extends React.Component {
// }
// componentWillUpdate(nextProps, nextState) {
// // Can't call this.setState() here, use componentWillReceiveProps instead
// }
// componentDidUpdate(prevProps, prevState) {
......
/* 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}&nbsp;</div>
{password_info && <div className="warning">{password_info}&nbsp;</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(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment