File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3535 "react-redux" : " *" ,
3636 "react-scripts" : " *" ,
3737 "recompose" : " *" ,
38- "typeface-roboto" : " *"
38+ "typeface-roboto" : " *" ,
39+ "zxcvbn" : " ^4.4.2"
3940 },
4041 "scripts" : {
4142 "start" : " cross-env PORT=3001 react-scripts start" ,
Original file line number Diff line number Diff line change @@ -14,6 +14,8 @@ import TextField from '@material-ui/core/TextField'
1414import DialogContentText from '@material-ui/core/DialogContentText'
1515import DialogTitle from '@material-ui/core/DialogTitle'
1616import { AppContext } from './MainFrame'
17+ import PasswordStrengthMeter from './PasswordStrengthMeter'
18+
1719import axios from 'axios'
1820
1921const style = ( theme ) => ( {
@@ -74,6 +76,9 @@ function Account(props) {
7476 const handleClose = ( ) => {
7577 setOpenPwdForm ( false )
7678 setErrorMessage ( '' )
79+ setOldPassword ( '' )
80+ setNewPassword ( '' )
81+ setConfirmedPassword ( '' )
7782 }
7883
7984 const onChangeOldPwd = ( e ) => {
@@ -264,6 +269,7 @@ function Account(props) {
264269 onChange = { onChangeNewPwd }
265270 value = { newPassword }
266271 />
272+ < PasswordStrengthMeter password = { newPassword } />
267273 < TextField
268274 variant = "outlined"
269275 margin = "normal"
Original file line number Diff line number Diff line change 1+ import React from 'react'
2+ import zxcvbn from 'zxcvbn'
3+ import { withStyles } from '@material-ui/core/styles'
4+ import LinearProgress from '@material-ui/core/LinearProgress'
5+ import Typography from '@material-ui/core/Typography'
6+ import classNames from 'classnames'
7+
8+ const styles = ( theme ) => ( {
9+ alert : {
10+ color : theme . palette . primary . main ,
11+ } ,
12+ } )
13+
14+ const PasswordStrengthMeter = ( props ) => {
15+ const { password, classes } = props
16+
17+ const pwdScore = zxcvbn ( password ) . score
18+
19+ const pwdAlert = ( pwdScore ) => {
20+ switch ( pwdScore ) {
21+ case 0 :
22+ return 'Too weak'
23+ case 1 :
24+ return 'Weak'
25+ case 2 :
26+ return 'Fair'
27+ case 3 :
28+ return 'Good'
29+ case 4 :
30+ return 'Strong'
31+ default :
32+ return 'Weak'
33+ }
34+ }
35+
36+ return (
37+ < >
38+ { password && (
39+ < >
40+ < LinearProgress
41+ variant = "determinate"
42+ color = { classNames ( pwdScore > 1 ? 'primary' : 'secondary' ) }
43+ value = { pwdScore * 25 }
44+ />
45+ < Typography className = { classes . alert } > { pwdAlert ( pwdScore ) } </ Typography >
46+ </ >
47+ ) }
48+ </ >
49+ )
50+ }
51+
52+ export default withStyles ( styles ) ( PasswordStrengthMeter )
You can’t perform that action at this time.
0 commit comments