Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed copy and password strength #3

Merged
merged 1 commit into from
Jan 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions ui/password-generator-tool/src/components/Generate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,28 @@ const Generate = () => {
const [number, setNumber] = useState(false)
const [specialCharacter, setSpecialCharacter] = useState(false)
const [passwordLength, setPasswordLength] = useState(8)
const [generatedPassword, setGeneratedPassword] = useState('eKs@4]sx3hq]')
const [generatedPassword, setGeneratedPassword] = useState('Configure your password')
const [sendToEmail, setSendToEmail] = useState(false)
const [targetEmail, setTargetEmail] = useState('')
const [copy, setCopied] = useState('COPY')
const [settings, setSettings] = useState(0)

useEffect(() => {
const characters = { capitalAlphabet, smallAlphabet, number, specialCharacter, passwordLength }
var count = 0
if (characters.capitalAlphabet) {
count += 1
}
if (characters.smallAlphabet) {
count += 1
}
if (characters.number) {
count += 1
}
if (characters.specialCharacter) {
count += 1
}
setSettings(count)
callGeneratePasswordApi(characters)
}, [capitalAlphabet, smallAlphabet, number, specialCharacter, passwordLength])

Expand All @@ -40,16 +56,30 @@ const Generate = () => {
<Col lg={5}>
<div className="d-flex justify-content-between mb-4">
<div className="fs-3 border-2 text-truncate text-center border-0">{generatedPassword}</div>
<label className="bg-success fw-bold rounded-4 py-2 px-4" style={{fontSize: "12px"}}>VERY STRONG</label>
{settings == 4 && (
<label className="fw-bold rounded-4 py-3 px-4 mb-2" style={{fontSize: "12px", color: "white", backgroundColor: "#006400"}}>VERY STRONG</label>
)}
{settings == 3 && (
<label className="bg-success fw-bold rounded-4 py-3 px-4 mb-2" style={{fontSize: "12px", color: "white"}}>STRONG</label>
)}
{settings == 2 && (
<label className="bg-warning fw-bold rounded-4 py-3 px-4 mb-2" style={{fontSize: "12px", color: "white"}}>GOOD</label>
)}
{settings <= 1 && (
<label className="bg-danger fw-bold rounded-4 py-3 px-4 mb-2" style={{fontSize: "12px", color: "white"}}>POOR</label>
)}
</div>
<button
className="btn btn-light shadow"
onClick={() => {
navigator.clipboard.writeText(generatedPassword)
alert("Copied!")
setCopied("COPIED")
setTimeout(function() {
setCopied("COPY")
}, 1000);
}}
>
<strong>COPY</strong>
<strong>{copy}</strong>
</button>
<div className="d-flex justify-content-between my-3">
<div className="text-capitalize">
Expand Down
Loading