-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword.html
More file actions
43 lines (43 loc) · 2.8 KB
/
password.html
File metadata and controls
43 lines (43 loc) · 2.8 KB
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
<!DOCTYPE html> <!-- Document type declaration -->
<html lang="en"> <!-- Language declaration -->
<head>
<meta charset="UTF-8"> <!-- Character encoding declaration -->
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Viewport declaration -->
<title>password</title> <!-- Title of the document -->
<link rel="stylesheet" href="password.css"> <!-- Link to external CSS file -->
</head>
<body>
<div class="container"> <!-- Container for the entire application -->
<h1>Generate a <br><span>random password</span></h1> <!-- Title of the password generation application -->
<div class="display"> <!-- Container for the password display -->
<input type="text" id="password" Placeholder="password"> <!-- Input field for displaying password -->
<img src="images/copy.png" onclick="copyPassword()"> <!-- Image for copying password -->
</div>
<button onclick="createPassword()"><img src="images/generate.png">Generate password</button> <!-- Button to generate password -->
</div>
<script>
const passwordBox=document.getElementById("password"); // Selecting password input field
const length=12; // Length of the generated password
const upperCase="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // Characters for uppercase letters
const lowerCase="abcdefghijklmnopqrstuvwxyz"; // Characters for lowercase letters
const number="0123456789"; // Characters for numbers
const symbol="@#$ù{}[]|`\^*/-+"; // Characters for symbols
const allChars=upperCase+lowerCase+number+symbol; // All possible characters for password generation
function createPassword(){ // Function to generate password
let password=""; // Initialize password variable
password+=upperCase[Math.floor(Math.random()*upperCase.length)]; // Add random uppercase letter to password
password+=lowerCase[Math.floor(Math.random()*lowerCase.length)]; // Add random lowercase letter to password
password+=number[Math.floor(Math.random()*number.length)]; // Add random number to password
password+=symbol[Math.floor(Math.random()*symbol.length)]; // Add random symbol to password
while (length>password.length) { // Loop until desired password length is reached
password+=allChars[Math.floor(Math.random()*allChars.length)]; // Add random character from all possible characters to password
}
passwordBox.value=password; // Display generated password in input field
}
function copyPassword() { // Function to copy password
passwordBox.select(); // Select the password text
document.execCommand("copy"); // Execute copy command
}
</script>
</body>
</html>