-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
33 lines (30 loc) · 1.08 KB
/
main.js
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
const passwordBox = document.getElementById("password");
const length = 12;
const upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const lowerCase = "abcdefghijklmnopqrstuvwxyz";
const number = "0123456789";
const symbol = "@#$%&*()_+~|}{[]></-=";
const alChars = upperCase + lowerCase + number + symbol;
function createPassword() {
let password = "";
password += upperCase[Math.floor(Math.random() * upperCase.length)];
password += lowerCase[Math.floor(Math.random() * lowerCase.length)];
password += number[Math.floor(Math.random() * number.length)];
password += symbol[Math.floor(Math.random() * symbol.length)];
while (length > password.length) {
password += alChars[Math.floor(Math.random() * alChars.length)];
}
passwordBox.value = password;
}
function copyPassword() {
passwordBox.select();
// Kopiert den ausgewählten Text in die Zwischenablage
navigator.clipboard
.writeText(passwordBox.value)
.then(() => {
console.log("Passwort wurde in die Zwischenablage kopiert.");
})
.catch((err) => {
console.error("Fehler beim Kopieren: ", err);
});
}