This file contains hidden or 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
| generatePassword = () => { | |
| ... | |
| this.setState({ | |
| password: passwordArray.join("") | |
| }, () => { | |
| this.checkPasswordStrength(); | |
| }) | |
| } |
This file contains hidden or 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
| checkPasswordStrength = () => { | |
| ... | |
| this.setState({ | |
| strengthScore: 10, | |
| strengthText: 'weak' | |
| }) | |
| } | |
| copyToClipboard = () => { | |
| ... | |
| this.setState({ |
This file contains hidden or 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
| <input | |
| id="length" | |
| type="range" | |
| min="6" | |
| className="range-slider" | |
| max={maxLength} | |
| value={length} | |
| onChange={(e) => this.handleOnChange(e, 'length')} | |
| /> |
This file contains hidden or 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
| function PasswordGenerator(props){ | |
| const [password, setPassword] = useState('') | |
| const [length, setLength] = useState(props.length) | |
| const [digitCount, setDigitCount] = useState(props.digitCount) | |
| const [symbolCount, setSymbolCount] = useState(props.symbolCount) | |
| const [copy, setCopy] = useState(false) | |
| const [strengthScore, setStrengthScore] = useState(0) | |
| const [strengthText, setStrengthText] = useState('') | |
| const [settings, setSettings] = useState({ | |
| maxLength: props.maxLength, |
This file contains hidden or 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
| useEffect(() => { | |
| document.getElementById("copy_btn").addEventListener("click", copyToClipboard); | |
| return () => { | |
| document.getElementById("copy_btn").removeEventListener("click", copyToClipboard); | |
| } | |
| }, []) | |
| useEffect(() => { | |
| generatePassword() | |
| checkPasswordStrength() |
This file contains hidden or 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
| const generatePassword = () => { | |
| ... | |
| setPassword(passwordArray.join("")) | |
| } |
This file contains hidden or 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
| const checkPasswordStrength = () => { | |
| ... | |
| setStrengthScore(10) | |
| setStrengthText('weak') | |
| } | |
| const copyToClipboard = () => { | |
| ... | |
| setCopy(true) | |
| setTimeout(() => { |
This file contains hidden or 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
| const handleOnChange = (e, name) => { | |
| let value = e.target.value | |
| if(name === 'length'){ | |
| setLength(value) | |
| }else if(name === 'digits'){ | |
| setDigitCount(value) | |
| }else if(name === 'symbols'){ | |
| setSymbolCount(value) | |
| } | |
| } |
This file contains hidden or 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
| PasswordGenerator.propTypes = { | |
| length: PropTypes.number, | |
| digitCount: PropTypes.number, | |
| symbolCount: PropTypes.number, | |
| maxLength: PropTypes.number, | |
| maxDigits: PropTypes.number, | |
| maxSymbols: PropTypes.number | |
| } | |
| PasswordGenerator.defaultProps = { |
This file contains hidden or 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
| <input type="number" value="2" min="0" max="40" /> |