Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 119 additions & 0 deletions index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
body {
margin: 80px 50px;
background-color: #1F2937;
font-family: Karla;
max-width: 500px;
max-height: 800px;
}

h1 {
color: #F0F9FF;
margin-bottom: 10px;
font-weight: 800;
}

p {
color: #D5D4D8;
margin-top: 5px;
font-family: Inter;
}

#header-highlight {
color: #38BDF8;
}

#pwOptions-div {
border: #7DD3FC solid 1px;
border-radius: 5px;
padding: 5px 10px;
color: #D5D4D8;
display: flex;
flex-direction: column;
}

.pwOption {
margin-top: 10px;
margin-bottom: 10px;
height: 30px;
}

#length-select {
background-color:#273549;
border-radius: 5px;
color: #D5D4D8;
margin-left: 10px;
border: #D5D4D8 solid 1px;
}

#specialchar-checkbox {
margin-left: 5px;
vertical-align: middle;
height: 18px;
width: 18px;
border: #D5D4D8 solid 2px;
}

#specialchar-checkbox:not(:checked) {
background-color: #0EA5E9;
accent-color: #D5D4D8;
}

#generate-btn {
font-family: Inter;
color: white;
margin-top: 25px;
margin-bottom: 25px;
background-color: #0EA5E9;
border-radius: 5px;
padding: 10px 15px;
border: 0px;
font-size: 14px;
}

hr {
border-color: #273549;
box-shadow: 0px 4px 4px #111827 ;
}


/* still not wide enough for all 25-char long passwords! */
#pw1-div, #pw2-div {
width: 230px;
height: 30px;
background-color: #273549;
border-radius: 5px;
color: #7DD3FC;
font-size: 14px;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}

#output-div {
margin-top: 25px;
display: flex;
justify-content: space-between;
}

#copyPw1-btn, #copyPw2-btn {
margin: 10px 10px;
width: 40px;
height: 40px;
padding: 3px;
background-color: #495969;
border-radius: 4px;
box-shadow: 1px 1px 2px #222222;
font-size: 20px;
}

#copy-message {
font-size: 10px;
color: lightgreen;
}

.pwcontainer {
display: flex;
flex-direction: column;
align-items: center;
}
60 changes: 60 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="index.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Karla:ital,wght@0,200..800;1,200..800&family=Open+Sans:ital,wght@0,300..800;1,300..800&display=swap" rel="stylesheet">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&family=Karla:ital,wght@0,200..800;1,200..800&family=Open+Sans:ital,wght@0,300..800;1,300..800&display=swap" rel="stylesheet">
</head>
<body>
<h1>Generate a <br><span id="header-highlight">random password</span></h1>
<p>Never use an insecure password again.</p>
<div id="pwOptions-div">
<div class="pwOption">
<label for="length-select">Password length:</label>
<select name="password-length" id="length-select">
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15" selected>15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
</select>
</div>
<div class="pwOption">
<label for="specialchar-checkbox">Include special characters</label>
<input type="checkbox" id="specialchar-checkbox" value="true" checked>
</div>
</div>
<button id="generate-btn">Generate passwords</button>
<hr/>
<div id="output-div">
<div class="pwcontainer">
<div id="pw1-div"></div>
<button id="copyPw1-btn" onclick="copyPw('pw1-div')">📋</button>
</div>
<div class="pwcontainer">
<div id="pw2-div"></div>
<button id="copyPw2-btn" onclick="copyPw('pw2-div')">📋</button>
</div>
</div>
<script src="index.js"></script>
</body>
</html>
51 changes: 51 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const characters = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9","~","`","!","@","#","$","%","^","&","*","(",")","_","-","+","=","{","[","}","]",",","|",":",";","<",">",".","?",
"/"];
//hook up button with password generator function
let buttonEl = document.getElementById("generate-btn")
buttonEl.addEventListener("click", generatePassword)


//function for retrieving password requirements set by user
function getPasswordReq() {
let lengthInput = document.getElementById("length-select")
let specialCharInput = document.getElementById("specialchar-checkbox").checked
//return object with password requirements
return {
length: +lengthInput.value,
specialChars: specialCharInput
}
}

function generatePassword() {
//get <div> elements to generate passwords into
let pw1El = document.getElementById("pw1-div")
let pw2El = document.getElementById("pw2-div")
//clear existing passwords
pw1El.textContent = ""
pw2El.textContent = ""
//set character range based on requirement on special characters
if (getPasswordReq().specialChars === true) {
var charRange = characters.length
}
else {
var charRange = characters.length - 29
}
// get random characters from array
for (i=1; i<(getPasswordReq().length +1); i++) {
let randomChar = Math.floor(Math.random()*charRange)
pw1El.textContent += characters[randomChar]
randomChar = Math.floor(Math.random()*charRange)
pw2El.textContent += characters[randomChar]
}
}


function copyPw(pwSelector) {
let copyText = document.getElementById(pwSelector)
// Copy the text inside the text field if it hasn't been copied already
if (copyText.textContent != "Password copied")
navigator.clipboard.writeText(copyText.textContent)
// Display confirmation message
copyText.textContent = "Password copied"
copyText.style.color = "lightgreen"
}