Skip to content

Commit 548460f

Browse files
Finish Video
0 parents  commit 548460f

3 files changed

Lines changed: 171 additions & 0 deletions

File tree

‎index.html‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<script src="script.js" defer></script>
8+
<link rel="stylesheet" href="styles.css">
9+
<title>Password Generator</title>
10+
</head>
11+
<body>
12+
<div class="container">
13+
<h1 class="title">Password Generator</h1>
14+
<h3 class="password-display" id="passwordDisplay">password</h3>
15+
<form id="passwordGeneratorForm" class="form">
16+
<label for="characterAmountNumber">Number Of Characters</label>
17+
<div class="character-amount-container">
18+
<input type="range" min="1" max="50" value="10" id="characterAmountRange">
19+
<input class="number-input" type="number" min="1" max="50" value="10" id="characterAmountNumber">
20+
</div>
21+
22+
<label for="includeUppercase">Include Uppercase</label>
23+
<input type="checkbox" id="includeUppercase">
24+
25+
<label for="includeNumbers">Include Numbers</label>
26+
<input type="checkbox" id="includeNumbers">
27+
28+
<label for="includeSymbols">Include Symbols</label>
29+
<input type="checkbox" id="includeSymbols">
30+
31+
<button type="submit" class="btn">Generate Password</button>
32+
</form>
33+
</div>
34+
</body>
35+
</html>

‎script.js‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const characterAmountRange = document.getElementById('characterAmountRange')
2+
const characterAmountNumber = document.getElementById('characterAmountNumber')
3+
const includeUppercaseElement = document.getElementById('includeUppercase')
4+
const includeNumbersElement = document.getElementById('includeNumbers')
5+
const includeSymbolsElement = document.getElementById('includeSymbols')
6+
const form = document.getElementById('passwordGeneratorForm')
7+
const passwordDisplay = document.getElementById('passwordDisplay')
8+
9+
const UPPERCASE_CHAR_CODES = arrayFromLowToHigh(65, 90)
10+
const LOWERCASE_CHAR_CODES = arrayFromLowToHigh(97, 122)
11+
const NUMBER_CHAR_CODES = arrayFromLowToHigh(48, 57)
12+
const SYMBOL_CHAR_CODES = arrayFromLowToHigh(33, 47).concat(
13+
arrayFromLowToHigh(58, 64)
14+
).concat(
15+
arrayFromLowToHigh(91, 96)
16+
).concat(
17+
arrayFromLowToHigh(123, 126)
18+
)
19+
20+
characterAmountNumber.addEventListener('input', syncCharacterAmount)
21+
characterAmountRange.addEventListener('input', syncCharacterAmount)
22+
23+
form.addEventListener('submit', e => {
24+
e.preventDefault()
25+
const characterAmount = characterAmountNumber.value
26+
const includeUppercase = includeUppercaseElement.checked
27+
const includeNumbers = includeNumbersElement.checked
28+
const includeSymbols = includeSymbolsElement.checked
29+
const password = generatePassword(characterAmount, includeUppercase, includeNumbers, includeSymbols)
30+
passwordDisplay.innerText = password
31+
})
32+
33+
function generatePassword(characterAmount, includeUppercase, includeNumbers, includeSymbols) {
34+
let charCodes = LOWERCASE_CHAR_CODES
35+
if (includeUppercase) charCodes = charCodes.concat(UPPERCASE_CHAR_CODES)
36+
if (includeSymbols) charCodes = charCodes.concat(SYMBOL_CHAR_CODES)
37+
if (includeNumbers) charCodes = charCodes.concat(NUMBER_CHAR_CODES)
38+
39+
const passwordCharacters = []
40+
for (let i = 0; i < characterAmount; i++) {
41+
const characterCode = charCodes[Math.floor(Math.random() * charCodes.length)]
42+
passwordCharacters.push(String.fromCharCode(characterCode))
43+
}
44+
return passwordCharacters.join('')
45+
}
46+
47+
function arrayFromLowToHigh(low, high) {
48+
const array = []
49+
for (let i = low; i <= high; i++) {
50+
array.push(i)
51+
}
52+
return array
53+
}
54+
55+
function syncCharacterAmount(e) {
56+
const value = e.target.value
57+
characterAmountNumber.value = value
58+
characterAmountRange.value = value
59+
}

‎styles.css‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
body {
2+
background-color: #333;
3+
margin: 0;
4+
color: white;
5+
min-height: 100vh;
6+
display: flex;
7+
justify-content: center;
8+
align-items: center;
9+
font-family: Georgia, 'Times New Roman', Times, serif;
10+
}
11+
12+
.container {
13+
background-color: #006699;
14+
padding: 3rem;
15+
border-radius: 1rem;
16+
border: 2px solid black;
17+
display: flex;
18+
justify-content: center;
19+
align-items: center;
20+
flex-direction: column;
21+
}
22+
23+
.form {
24+
display: grid;
25+
grid-template-columns: auto auto;
26+
row-gap: 1rem;
27+
column-gap: 3rem;
28+
justify-content: center;
29+
align-items: center;
30+
}
31+
32+
.title {
33+
margin: 0;
34+
text-align: center;
35+
}
36+
37+
label {
38+
font-weight: bold;
39+
}
40+
41+
.character-amount-container {
42+
display: flex;
43+
align-items: center;
44+
}
45+
46+
.number-input {
47+
width: 2rem;
48+
}
49+
50+
.password-display {
51+
background-color: white;
52+
color: black;
53+
padding: 1rem;
54+
border: 1px solid #333;
55+
height: 2rem;
56+
width: 350px;
57+
display: flex;
58+
justify-content: center;
59+
align-items: center;
60+
word-break: break-all;
61+
border-radius: .5rem;
62+
}
63+
64+
.btn {
65+
grid-column: span 2;
66+
background-color: transparent;
67+
border: 2px solid white;
68+
color: white;
69+
padding: .5rem 1rem;
70+
font-weight: bold;
71+
cursor: pointer;
72+
border-radius: 1rem;
73+
}
74+
75+
.btn:hover {
76+
background-color: #FFFFFF33;
77+
}

0 commit comments

Comments
 (0)