Skip to content

Instantly share code, notes, and snippets.

@ovpv
Created September 2, 2019 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ovpv/62323691a125b953614e9181744b5f2b to your computer and use it in GitHub Desktop.
Save ovpv/62323691a125b953614e9181744b5f2b to your computer and use it in GitHub Desktop.
Password component definition
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