1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/** @jsxImportSource https://esm.sh/react */
import React, { useState } from "https://esm.sh/react";
import { createRoot } from "https://esm.sh/react-dom/client";
function App() {
const [password, setPassword] = useState("");
const [length, setLength] = useState(12);
const [includeUppercase, setIncludeUppercase] = useState(true);
const [includeLowercase, setIncludeLowercase] = useState(true);
const [includeNumbers, setIncludeNumbers] = useState(true);
const [includeSymbols, setIncludeSymbols] = useState(true);
const generatePassword = () => {
let charset = "";
if (includeUppercase) charset += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if (includeLowercase) charset += "abcdefghijklmnopqrstuvwxyz";
if (includeNumbers) charset += "0123456789";
if (includeSymbols) charset += "!@#$%^&*()_+~`|}{[]:;?><,./-=";
if (charset === "") {
setPassword("Please select at least one character type");
return;
}
const array = new Uint32Array(length);
crypto.getRandomValues(array);
const password = Array.from(array)
.map(x => charset[x % charset.length])
.join('');
setPassword(password);
};
return (
<div className="container mx-auto p-4">
<h1 className="text-2xl font-bold mb-4">Password Generator</h1>
<div className="mb-4">
<label className="block mb-2">Password Length: {length}</label>
<input
type="range"
min="8"
max="32"
value={length}
onChange={(e) => setLength(Number(e.target.value))}
className="w-full"
/>
</div>
<div className="mb-4">
<label className="inline-flex items-center">
<input
type="checkbox"
checked={includeUppercase}
onChange={() => setIncludeUppercase(!includeUppercase)}
className="form-checkbox"
/>
<span className="ml-2">Include Uppercase</span>
</label>
</div>
<div className="mb-4">
<label className="inline-flex items-center">
<input
type="checkbox"
checked={includeLowercase}
onChange={() => setIncludeLowercase(!includeLowercase)}
className="form-checkbox"
/>
<span className="ml-2">Include Lowercase</span>
</label>
</div>
<div className="mb-4">
<label className="inline-flex items-center">
<input
type="checkbox"
checked={includeNumbers}
onChange={() => setIncludeNumbers(!includeNumbers)}
className="form-checkbox"
/>
<span className="ml-2">Include Numbers</span>
</label>
</div>
<div className="mb-4">
<label className="inline-flex items-center">
<input
type="checkbox"
checked={includeSymbols}
onChange={() => setIncludeSymbols(!includeSymbols)}
className="form-checkbox"
/>
<span className="ml-2">Include Symbols</span>
</label>
</div>
<button
onClick={generatePassword}
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
>
Generate Password
</button>
{password && (
<div className="mt-4">
<h2 className="text-xl font-semibold">Generated Password:</h2>
<p className="bg-gray-100 p-2 rounded mt-2 font-mono">{password}</p>