Skip to content

Instantly share code, notes, and snippets.

@ovpv

ovpv/password.js

Created Sep 2, 2019
Embed
What would you like to do?
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