Skip to content

Commit

Permalink
Add protection against insecure passwords
Browse files Browse the repository at this point in the history
  • Loading branch information
belcherj authored and codebykat committed May 15, 2020
1 parent 6aaefd3 commit 4e6a8de
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/auth/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { viewExternalUrl } from '../utils/url-utils';

type OwnProps = {
authPending: boolean;
hasInsecurePassword: boolean;
hasInvalidCredentials: boolean;
hasLoginError: boolean;
login: (username: string, password: string) => any;
Expand Down Expand Up @@ -76,6 +77,25 @@ export class Auth extends Component<Props> {
{!this.state.onLine && (
<p className="login__auth-message is-error">Offline</p>
)}
{this.props.hasInsecurePassword && (
<p
className="login__auth-message is-error"
data-error-name="invalid-login"
>
Your password is insecure and must be
<a
className="login__reset"
href="https://app.simplenote.com/reset/"
target="_blank"
rel="noopener noreferrer"
onClick={this.onForgot}
>
reset
</a>
. The password requirements are: Password cannot match email,
Between 8 and 64 characters, No new lines, and No tabs
</p>
)}
{this.props.hasInvalidCredentials && (
<p
className="login__auth-message is-error"
Expand Down
6 changes: 6 additions & 0 deletions lib/boot-without-auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { render } from 'react-dom';
import { Auth as AuthApp } from './auth';
import { Auth as SimperiumAuth } from 'simperium';
import analytics from './analytics';
import { validatePassword } from '../utils/validate-password';

import getConfig from '../get-config';

Expand All @@ -16,6 +17,7 @@ type State = {
authStatus:
| 'unsubmitted'
| 'submitting'
| 'insecure-password'
| 'invalid-credentials'
| 'unknown-error';
};
Expand All @@ -42,6 +44,9 @@ class AppWithoutAuth extends Component<Props, State> {
auth
.authorize(username, password)
.then((user: User) => {
if (!validatePassword(password, username)) {
this.setState({ authStatus: 'insecure-password' });
}
if (!user.access_token) {
throw new Error('missing access token');
}
Expand Down Expand Up @@ -96,6 +101,7 @@ class AppWithoutAuth extends Component<Props, State> {
<div className={`app theme-${systemTheme}`}>
<AuthApp
authPending={this.state.authStatus === 'submitting'}
hasInsecurePassword={this.state.authStatus === 'insecure-password'}
hasInvalidCredentials={
this.state.authStatus === 'invalid-credentials'
}
Expand Down

0 comments on commit 4e6a8de

Please sign in to comment.