2017-09-28 03:37:33 -05:00
|
|
|
import React from 'react';
|
2017-09-21 06:32:57 -05:00
|
|
|
|
2018-08-24 09:48:47 -05:00
|
|
|
export interface Props {
|
2017-09-21 06:32:57 -05:00
|
|
|
password: string;
|
|
|
|
}
|
|
|
|
|
2018-08-24 09:48:47 -05:00
|
|
|
export class PasswordStrength extends React.Component<Props, any> {
|
2017-09-21 06:32:57 -05:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2017-12-13 02:09:58 -06:00
|
|
|
const { password } = this.props;
|
2018-08-24 09:48:47 -05:00
|
|
|
let strengthText = 'strength: strong like a bull.';
|
|
|
|
let strengthClass = 'password-strength-good';
|
2017-09-21 06:32:57 -05:00
|
|
|
|
2017-12-13 02:09:58 -06:00
|
|
|
if (!password) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (password.length <= 8) {
|
2018-08-24 09:48:47 -05:00
|
|
|
strengthText = 'strength: you can do better.';
|
|
|
|
strengthClass = 'password-strength-ok';
|
2017-09-21 06:32:57 -05:00
|
|
|
}
|
|
|
|
|
2017-12-13 02:09:58 -06:00
|
|
|
if (password.length < 4) {
|
2018-08-24 09:48:47 -05:00
|
|
|
strengthText = 'strength: weak sauce.';
|
|
|
|
strengthClass = 'password-strength-bad';
|
2017-10-01 13:02:25 -05:00
|
|
|
}
|
|
|
|
|
2017-09-21 06:32:57 -05:00
|
|
|
return (
|
|
|
|
<div className={`password-strength small ${strengthClass}`}>
|
|
|
|
<em>{strengthText}</em>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|