Last active
May 25, 2022 12:08
-
-
Save dantetesta/5f3aa0d003ba8fff1cc09c24f28ebc80 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*BY: ASK JARVIS + DANTE TESTA */ | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Password Generator</title> | |
<style> | |
body { | |
background-color: #f0f0f0; | |
} | |
.container { | |
width: 500px; | |
margin: 0 auto; | |
background-color: #fff; | |
padding: 20px; | |
border-radius: 10px; | |
box-shadow: 0 0 10px rgba(0,0,0,0.5); | |
} | |
.container h1 { | |
text-align: center; | |
margin-bottom: 20px; | |
} | |
.container label { | |
display: block; | |
margin-bottom: 10px; | |
} | |
.container input[type="range"] { | |
width: 100%; | |
} | |
.container input[type="checkbox"] { | |
margin-right: 10px; | |
} | |
.container input[type="button"] { | |
width: 100%; | |
padding: 10px; | |
border: none; | |
border-radius: 5px; | |
background-color: #00a8ff; | |
color: #fff; | |
font-weight: bold; | |
cursor: pointer; | |
} | |
.container input[type="button"]:hover { | |
background-color: #00bfff; | |
} | |
.container #password { | |
width: 100%; | |
padding: 10px; | |
border: none; | |
border-radius: 5px; | |
color: #000; | |
font-weight: bold; | |
cursor: pointer; | |
font-size: 25px; | |
text-align: center; | |
} | |
</style> | |
</head> | |
<body> | |
<div class="container"> | |
<h1>Password Generator</h1> | |
<label for="range">Password Length: <span id="range-value"></span></label> | |
<input type="range" id="range" min="4" max="32" value="8"> | |
<br> | |
<label>Password Options:</label> | |
<input type="checkbox" id="uppercase"> | |
<label for="uppercase">Uppercase</label> | |
<input type="checkbox" id="lowercase"> | |
<label for="lowercase">Lowercase</label> | |
<input type="checkbox" id="numbers"> | |
<label for="numbers">Numbers</label> | |
<input type="checkbox" id="special"> | |
<label for="special">Special Characters</label> | |
<br> | |
<input type="button" value="Generate Password" id="generate"> | |
<br> | |
<div id="password"></div> | |
</div> | |
<script> | |
const range = document.getElementById('range'); | |
const rangeValue = document.getElementById('range-value'); | |
const uppercase = document.getElementById('uppercase'); | |
const lowercase = document.getElementById('lowercase'); | |
const numbers = document.getElementById('numbers'); | |
const special = document.getElementById('special'); | |
const generate = document.getElementById('generate'); | |
const password = document.getElementById('password'); | |
rangeValue.innerHTML = range.value; | |
range.addEventListener('input', () => { | |
rangeValue.innerHTML = range.value; | |
}); | |
generate.addEventListener('click', () => { | |
let passwordValue = ''; | |
const uppercaseValue = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; | |
const lowercaseValue = 'abcdefghijklmnopqrstuvwxyz'; | |
const numbersValue = '0123456789'; | |
const specialValue = '@&?#%!+*/'; | |
if (uppercase.checked) { | |
passwordValue += uppercaseValue; | |
} | |
if (lowercase.checked) { | |
passwordValue += lowercaseValue; | |
} | |
if (numbers.checked) { | |
passwordValue += numbersValue; | |
} | |
if (special.checked) { | |
passwordValue += specialValue; | |
} | |
let passwordText = ''; | |
for (let i = 0; i < range.value; i++) { | |
passwordText += passwordValue[Math.floor(Math.random() * passwordValue.length)]; | |
} | |
if(passwordValue!=''){ | |
password.innerHTML = passwordText; | |
} | |
}); | |
password.addEventListener('click', () => { | |
const textArea = document.createElement('textarea'); | |
const passwordText = password.innerHTML; | |
if (!passwordText) { | |
return; | |
} | |
textArea.value = passwordText; | |
document.body.appendChild(textArea); | |
textArea.select(); | |
document.execCommand('copy'); | |
textArea.remove(); | |
password.innerHTML = 'Copiado!'; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment