Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Password Generator</title>
    
    <link href="https://fonts.googleapis.com/css?family=Kanit&display=swap" rel="stylesheet">

    <script defer src="script.js"></script>
    <link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
        <h2 class="header">Password Generator</h2>
        <div class="password-display" id="password-display">
          <h3>Password</h3>
          
        </div> 
        <button class="copyButton" onclick="copyButton()">Copy</button>
        <p class="paragraph">Click inputs to generate password</p>

        <form id="passwordGeneratorForm" class="form">
                <div class="password-range">
                        <input type="range" value="10" id="characterAmountRange" min="10" max="50" list="ranges">
                        <input type="number" value="10" id="numberInput"  min="10" max="50">
                    </div>
              
                    <div class="controls">
                          <input type="checkbox" id="includeUpperCase">
                          <label for="includeUppercase">Use UpperCase Letters</label>
                    </div>
                    <div class="controls">
                          <input type="checkbox" id="includeSymbols">
                          <label for="includeSpecialChar">Use Special Characters</label>
                    </div>
                    <div class="controls">
                          <input type="checkbox" id="includeNumbers">
                          <label for="includeNumbers">Use Numbers</label>
                    </div>
                    <div class="generate-button">
                        <button class="btn" id="generate-button" type="submit">Generate</button>
                    </div>
            
        </form>
        
</div>
        

</body>
</html>
              
            
!

CSS

              
                body {
    display: flex;
    justify-content: center;
    min-height: 100vh;
    margin: 0;
    flex-direction: column;
    align-items: center;
    background-color: #455462;
    font-family: 'Kanit', sans-serif;
}
.container{
    display: flex;
    justify-content: center;
    align-content: center;
    flex-direction: column;
    border-style: solid;
    border-radius: 1rem;
    border-color: white;
    border-width: 1rem;
    padding: 5rem;
    background-color: 	#d6d9dd;
}
.header {
    text-align: center;
    color: black;
    
}
.paragraph {
    color: black
}

.password-display {
    background-color: white;
    color: black;
    border-style: solid;
    border-color: black;
    border-radius: 1em;
    display: flex;
    justify-content: center;
    align-items: center;
}
.password-range{
    display: flex;
    justify-content: center;
    padding: 30px;
    }


.generate-button{
display: flex;
justify-content: center;

}

.copyButton {
    font-size: 10px;
    border-style: solid;
    border-color: black;
    padding:  1em 1em 1em;
    
    border-radius: 1em
}
.btn {
    font-size: 15px;
    border-style: solid;
    border-color: black;
    padding:  1em 2em 1em;
    margin-top: 1em;
    border-radius: 1em

}



              
            
!

JS

              
                const characterRange = document.getElementById('characterAmountRange')
const numberInput = document.getElementById('numberInput')
const upperCaseInput = document.getElementById('includeUpperCase')
const numbersElement = document.getElementById('includeNumbers')
const symbolsElement = document.getElementById('includeSymbols')
const form = document.getElementById('passwordGeneratorForm')
const passWordDisplay = document.getElementById('password-display')

const LOWER_CASE_CHAR_CODES = arrayLowToHigh(97, 112)
const UPPER_CASE_CHAR_CODES = arrayLowToHigh(65, 90)
const NUMBER_CHAR_CODES = arrayLowToHigh(48, 57)
const SYMBOL_CHAR_CODES = arrayLowToHigh(58, 64).concat(
    arrayLowToHigh(91,96)
).concat(
    arrayLowToHigh(123, 126)
)


characterRange.addEventListener('input', syncInputs)
numberInput.addEventListener('input', syncInputs)

form.addEventListener('submit', e =>{
    e.preventDefault()
    const characterAmount = numberInput.value
    const includeUpperCase = upperCaseInput.checked
    const includeNumbers =  numbersElement.checked
    const includeSymbols = symbolsElement.checked
    const password = generatePassword(characterAmount, includeUpperCase, includeNumbers, includeSymbols)
    passWordDisplay.innerText = password
    
})

function generatePassword(characterAmount, includeUpperCase, includeNumbers, includeSymbols){
    let charCodes = LOWER_CASE_CHAR_CODES
    if(includeUpperCase) charCodes = charCodes.concat(UPPER_CASE_CHAR_CODES)
    if(includeNumbers) charCodes = charCodes.concat(NUMBER_CHAR_CODES)
    if(includeSymbols) charCodes = charCodes.concat(SYMBOL_CHAR_CODES)
    const passwordCharacters = []
    for(let i = 0; i < characterAmount; i ++){
        const characterCode = charCodes[Math.floor(Math.random() * charCodes.length)]
        passwordCharacters.push(String.fromCharCode(characterCode))
    }
    return passwordCharacters.join('')
}

function copyButton(){
    var copyText = passWordDisplay.innerText
      if(passWordDisplay.innerText === 'Password'){
        return 
      }    navigator.clipboard.writeText(copyText).then(function() {
      console.log('Async: Copying to clipboard was successful!');
    }, function(err) {
      console.error('Async: Could not copy text: ', err);
    });
    alert("Text was copied")
}


function arrayLowToHigh(low, high){
    const array = []
    for(let i = low; i <= high; i++){
        array.push(i)
    }
    return array
}

// Syncronizes range and number input
function syncInputs(e){
    const value = e.target.value
    characterRange.value = value
    numberInput.value = value
}
              
            
!
999px

Console