Created
September 2, 2019 13:43
-
-
Save ovpv/62323691a125b953614e9181744b5f2b to your computer and use it in GitHub Desktop.
Password component definition
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Password extends React.Component{ | |
constructor(){ | |
super(); | |
this.state = { | |
value: 0, | |
password:"" | |
} | |
} | |
updatePasswordvalue = (ev) => { | |
this.setState({ | |
password: ev.target.value | |
}); | |
this.changeMeterValue(); | |
} | |
changeMeterValue = () => { | |
const StrongPassword = new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})"); | |
const MediumPassword = new RegExp("^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})"); | |
if(this.state.password.length === 1){ | |
this.setState({ | |
value: 0 | |
}) | |
}else{ | |
if(StrongPassword.test(this.state.password)){ | |
this.setState({ | |
value: 100 | |
}) | |
}else{ if(MediumPassword.test(this.state.password)){ | |
this.setState({ | |
value: 50 | |
}) | |
}else{ | |
this.setState({ | |
value: 10 | |
}) | |
} | |
} | |
} | |
} | |
render(){ | |
return ( | |
<div className="d-md-flex flex-column"> | |
<input type="password" onChange={this.updatePasswordvalue} className="password"/> | |
{this.props.meter ? <Meter value={this.state.value} /> : <span>No Meter</span>} | |
{this.state.value} | |
</div> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment