The content on this website, including videos and code examples, is for educational purposes only. All demonstrations and designs are fictional and created to illustrate coding techniques. Any resemblance to existing websites or brands is purely coincidental.
The creators and administrators of this website do not claim ownership or affiliation with any existing websites or companies. Users are encouraged to use the information responsibly for learning purposes. Liability for any misuse of the content provided is not accepted.
Below is the html code for this video.
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css" />
<script type="text/javascript" src="index.js"></script>
<title>Password Generator</title>
</head>
<body>
<div class="container">
<h1 class="title">Password Generator</h1>
<div class="inner-container">
<label class="text-capitalize lh-30 f-18">Password length</label>
<input type="number" id="passwordLength" class="ml-auto" value="8" />
</div>
<div class="inner-container">
<label class="text-capitalize lh-30 f-18">Include uppercase characters</label>
<input type="checkbox" id="upperCaseCheckbox" class="ml-auto" checked />
</div>
<div class="inner-container">
<label class="text-capitalize lh-30 f-18">Include lowercase characters</label>
<input type="checkbox" id="lowerCaseCheckbox" class="ml-auto" checked />
</div>
<div class="inner-container">
<label class="text-capitalize lh-30 f-18">Include numbers</label>
<input type="checkbox" id="numbersCheckbox" class="ml-auto" checked />
</div>
<div class="inner-container">
<label class="text-capitalize lh-30 f-18">Include special characters</label>
<input type="checkbox" id="specialCharactersCheckbox" class="ml-auto" checked />
</div>
<div class="btn-container">
<button class="btn-gen-pwd" onclick="passwordGenerator()" id="generatePasswordButton">
Generate Password
</button>
</div>
<div class="inner-container">
<p class="text-capitalize lh-30 f-18">Generated Password</p>
<p class="ml-auto lh-30" id="passwordText"></p>
</div>
</div>
</body>
</html>
Below is the css code for this video.
style.css
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
background-image: linear-gradient(#a6c0fe, #f68084);
}
.container {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translate(-50%, -50%);
transform: translate(-50%, -50%);
width: 33%;
box-shadow: 0 0 50px 50px #dadada;
background-color: #dadada;
}
.title {
text-align: center;
font-size: 35px;
}
.inner-container {
width: 100%;
display: flex;
margin: 10px 0;
letter-spacing: 1px;
}
.btn-container {
width: 100%;
display: inline-block;
margin: 20px 0 0;
}
.ml-auto {
margin-left: auto;
}
.lh-30 {
line-height: 30px;
}
.f-18 {
font-size: 18px;
}
.text-capitalize {
text-transform: capitalize;
}
input[type=number] {
width: 25%;
background-color: transparent;
border: none;
border-bottom: 1px solid #000;
}
input[type=number]::-webkit-inner-spin-button {
-moz-appearance: textfield;
-webkit-appearance: none;
margin: 0;
}
input[type=checkbox] {
width: 1em;
height: 1em;
}
.btn-gen-pwd {
width: 100%;
display: inline-block;
padding: 10px 20px;
margin: 0;
font-size: 20px;
text-align: center;
cursor: pointer;
outline: none;
color: #fff;
text-transform: capitalize;
background-image: linear-gradient(#30cfd0, #330867);
border: none;
border-radius: 15px;
text-decoration: none;
box-shadow: 0 5px 10px 5px #adadad;
}
.btn-gen-pwd:hover {
box-shadow: 0 5px 10px -5px #777;
}
Below is the javascript code for this video.
index.js
const generatePasswordButton = document.getElementById("generatePasswordButton");
function passwordGenerator() {
const passwordText = document.getElementById("passwordText");
const passwordLength = document.getElementById("passwordLength");
const upperCaseCheckbox = document.getElementById("upperCaseCheckbox");
const lowerCaseCheckbox = document.getElementById("lowerCaseCheckbox");
const numbersCheckbox = document.getElementById("numbersCheckbox");
const specialCharactersCheckbox = document.getElementById("specialCharactersCheckbox");
const length = +passwordLength.value;
if (length > 24 || length < 4) {
passwordLength.value = "8";
return alert("Password should be between 4 to 24 characters");
}
const isUpperCase = upperCaseCheckbox.checked;
const isLowerCase = lowerCaseCheckbox.checked;
const isNumbers = numbersCheckbox.checked;
const isSpecialCharacters = specialCharactersCheckbox.checked;
passwordText.innerHTML = generatedPassword(isUpperCase, isLowerCase, isNumbers, isSpecialCharacters, length);
}
function generatedPassword(upperCase, lowerCase, numbers, specialCharacters, requiredPasswordLength) {
let password = "";
const totalTypes = upperCase + lowerCase + numbers + specialCharacters;
const arrayOfTypes = [{ upperCase }, { lowerCase }, { numbers }, { specialCharacters }]
.filter(item => Object.values(item)[0]);
if (totalTypes === 0) return "";
for (let iterator = 0; iterator < requiredPasswordLength; iterator += totalTypes) {
arrayOfTypes.forEach(eachType => {
const type = Object.keys(eachType)[0];
switch (type) {
case "upperCase":
password += getRandomUpperCaseCharacter();
break;
case "lowerCase":
password += getRandomLowerCaseCharacter();
break;
case "numbers":
password += getRandomNumbers();
break;
case "specialCharacters":
password += getRandomSpecialCharacters();
break;
}
});
}
return password;
}
function getRandomUpperCaseCharacter() {
const upperCaseCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
return upperCaseCharacters[Math.floor(Math.random() * upperCaseCharacters.length)];
}
function getRandomLowerCaseCharacter() {
const lowerCaseCharacters = "abcdefghijjklmnopqrstuvwxyz";
return lowerCaseCharacters[Math.floor(Math.random() * lowerCaseCharacters.length)];
}
function getRandomNumbers() {
const numbers = "0123456789";
return numbers[Math.floor(Math.random() * numbers.length)];
}
function getRandomSpecialCharacters() {
const specialCharacters = "@#$";
return specialCharacters[Math.floor(Math.random() * specialCharacters.length)];
}
Thanks for visiting