-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature update: strength indicator for new password
- Loading branch information
1 parent
147ff15
commit 6aeae25
Showing
2 changed files
with
44 additions
and
4 deletions.
There are no files selected for viewing
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
39 changes: 39 additions & 0 deletions
39
src/projects/06-password-generator/components/StrengthChecker.jsx
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
const StrengthChecker = ({ length, checkboxData }) => { | ||
const [strength, setStrength] = useState(''); | ||
|
||
useEffect(() => { | ||
const charTypeCount = checkboxData.reduce((acc, curr) => { | ||
if (curr.state) { | ||
acc++; | ||
} | ||
return acc; | ||
}, 0); | ||
|
||
if (length < 5 && charTypeCount === 1) { | ||
setStrength('very weak'); | ||
} else if (length < 7 && charTypeCount <= 2) { | ||
setStrength('weak'); | ||
} else if (length < 9 && charTypeCount <= 2) { | ||
setStrength('good'); | ||
} else if (length <= 9 && charTypeCount <= 3) { | ||
setStrength('very good'); | ||
} else if (length <= 15 && charTypeCount <= 1) { | ||
setStrength('good'); | ||
} else if (length <= 15 && charTypeCount <= 3) { | ||
setStrength('Excellent'); | ||
} else if (length <= 20 && charTypeCount <= 4) { | ||
setStrength('super strong'); | ||
} else { | ||
setStrength(''); | ||
} | ||
}, [length, checkboxData]); | ||
return ( | ||
<div className="strength"> | ||
<span>strength:</span> | ||
<span>{strength}</span> | ||
</div> | ||
); | ||
}; | ||
export default StrengthChecker; |