Passed
Push — main ( c7f79a...9585c1 )
by LCS
02:57
created

src/tools/PasswordGenerator.tsx   A

Complexity

Total Complexity 2
Complexity/F 2

Size

Lines of Code 24
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 20
mnd 1
bc 1
fnc 1
dl 0
loc 24
bpm 1
cpm 2
noi 0
c 0
b 0
f 0
rs 10

1 Function

Rating   Name   Duplication   Size   Complexity  
A PasswordGenerator.tsx ➔ PasswordGenerator 0 21 2
1
import { useState } from "react";
2
3
export default function PasswordGenerator() {
4
  const [length, setLength] = useState(12);
5
  const [result, setResult] = useState("");
6
7
  const generatePassword = () => {
8
    const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%";
9
    let password = "";
10
    for (let i = 0; i < length; i++) {
11
      password += charset.charAt(Math.floor(Math.random() * charset.length));
12
    }
13
    setResult(password);
14
  };
15
16
  return (
17
    <div>
18
      <h2>Password Generator</h2>
19
      <input type="number" value={length} onChange={(e) => setLength(Number(e.target.value))} min={4} max={50} />
20
      <button onClick={generatePassword}>Generate</button>
21
      <input type="text" value={result} readOnly />
22
    </div>
23
  );
24
}