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

              
                <main>
    <section class="tool" id="password-generator">
        <div class="header">Password Generator</div>

        <form>
            <div class="content">

                <div class="input-row">
                    <label for="template">Security<br>Template</label>
                    <select class="template" name="template">
                        <option value="custom">Custom</option>
                    </select>
                </div>

                <div class="input-row">
                    <label for="pass-length">Length<br>(4&ndash;256)</label>
                    <input class="pass-length" type="number" name="pass-length" value="16" />
                </div>

                <div class="input-group">
                    <div class="input-row">
                        <label>Valid<br>Characters</label>
                        <label class="inline" style="text-transform: none;"><input type="checkbox" class="alpha-lower" name="alpha-lower" checked>a&ndash;z</label><!--
                     --><label class="inline"><input type="checkbox" class="alpha-upper" name="alpha-upper" checked>A&ndash;Z</label><!--
                     --><label class="inline"><input type="checkbox" class="numbers" name="numbers" checked>0&ndash;9</label>
                    </div>
                    <div class="input-row">
                        <label class="inline"><input type="checkbox" class="symbols" name="symbols">Symbols</label><!--
                     --><label class="inline"><input type="checkbox" class="spaces" name="spaces">Spaces</label><!--
                     --><label class="inline"><input type="checkbox" class="similar" name="similar" checked>Similar</label>
                    </div>
                </div>

                <textarea name="password" class="password-output" resizeable=false readonly></textarea>
            </div>

            <div class="actions">
                <button class="generate action" type="submit">Generate</button>
            </div>

            <div class="snackbar">
                <div class="error message"></div>
            </div>
        </form>
    </section>
</main>
              
            
!

CSS

              
                * {
    outline: 0;
    margin: 0;
    border: 0;
    padding: 0;
    box-sizing: border-box;
}

body { background-color: hsl(0, 0%, 92.5%); }

main {
    font-family: Open Sans, sans-serif;
    font-size: 14px;
    padding: 50px;
    text-align: center;

    .tool {
        display: inline-block;
        vertical-align: top;
        margin: 10px;
        border-radius: 2px;
        width: 300px;
        box-shadow: 0px 1px 5px hsla(0, 0%, 0%, 0.3);
        background-color: hsl(0, 0%, 100%);

        .header {
            padding: 15px 10px;
            font: 400 16px/20px Open Sans, sans-serif;
            color: hsl(0, 0%, 100%);
            text-align: left;
            background-color: hsl(0, 0%, 30%);
        }

        .content {
            padding: 0 10px 10px;

            .input-group {
                border-bottom: 1px solid hsl(0, 0%, 90%);
                
                .date {

                    .year {
                        width: 50px;
                    }
                }
            }

            .input-row {
                border-bottom: 1px solid hsl(0, 0%, 90%);
                height: 50px;
                text-align: right;

                &.left-aligned { text-align: left; }

                &:last-of-type { border: none; }

                label {
                    font: 12px/16px Open Sans, sans-serif;
                    color: hsl(0, 0%, 60%);
                    text-transform: uppercase;

                    &:not(.inline) {
                        float: left;
                        padding: 9px 0;
                        text-align: left;
                    }

                    &.inline {
                        border-right: 1px solid hsl(0, 0%, 90%);
                        padding: 9px;
                        line-height: 50px;
                        &:last-of-type { border: none; }
                    }
                }

                input[type="text"], 
                input[type="number"], 
                select {
                    border: 0;
                    border-radius: 0;
                    min-width: 50px;
                    height: 100%;
                    font-size: 14px;
                    text-align: center;
                    color: hsl(0, 0%, 40%);
                    background-color: hsla(0, 0%, 0%, 0);
                }

                input[type="number"] {
                    -moz-appearance:textfield;
                }

                input::-webkit-outer-spin-button,
                input::-webkit-inner-spin-button {
                    -webkit-appearance: none;
                }

                input[type="radio"],
                input[type="checkbox"] {
                    margin-right: 10px;
                }
            }
        }

        .actions {
            padding: 5px;
            text-align: right;

            .action {
                display: inline-block;
                margin: 0 5px;
                border: none;
                padding: 10px 5px;
                cursor: pointer;
                font: 600 12px/16px Open Sans, sans-serif;
                text-transform: uppercase;
                letter-spacing: 1px;
                background-color: transparent;
                -moz-user-select: none;
                -webkit-user-select: none;
                -ms-user-select: none;

                &.disabled {
                    color: hsl(0, 0%, 75%)!important;
                    cursor: default;
                }
            }
        }

        .snackbar {
            display: none;
            padding: 10px;
            font: 400 12px/16px Open Sans, sans-serif;
            color: hsl(0, 100%, 100%);
            text-align: left;
            background-color: hsl(0, 0%, 15%);
        }
    }
}

#password-generator {
    text-align: left;

    .header {
        background-color: hsl(0, 60%, 40%);
    }

    .content {
        
        .input-row {

            .pass-length {
                width: 50px;
            }
        }

        .password-output {
            margin-top: 10px;
            border-radius: 2px;
            padding: 5px;
            width: 100%;
            height: 75px;
            font: 14px courier;
            color: hsl(0, 60%, 40%);
            box-shadow: 0px 1px 5px hsla(0, 0%, 0%, 0.3);
            resize: none;
            &::selection { background: hsl(0, 60%, 90%); }
            &::-moz-selection { background: hsl(0, 60%, 90%); }
        }
    }

    .actions {

        .action {
            color: hsl(0, 60%, 40%);
        }
    }
}
              
            
!

JS

              
                $(function() {
    // Define potential password characters
    var alphaLower = 'abcdefghijklmnopqrstuvwxyz';
    var alphaUpper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    var numbers    = '1234567890';
    var symbols    = '`~!@#$%^&*()_-+={}[]\\|:;\"\'<>,.?/';
    var spaces     = ' ';

    // Define presets
    var presets = {
        'WEP (64-bit)': {
            'pass-length': 5,
            'alpha-lower': true,
            'alpha-upper': true,
            'numbers': true,
            'symbols': true,
            'spaces': true,
            'similar': true
        },
        'WEP (128-bit)': {
            'pass-length': 13,
            'alpha-lower': true,
            'alpha-upper': true,
            'numbers': true,
            'symbols': true,
            'spaces': true,
            'similar': true
        },
        'WEP (152-bit)': {
            'pass-length': 16,
            'alpha-lower': true,
            'alpha-upper': true,
            'numbers': true,
            'symbols': true,
            'spaces': true,
            'similar': true
        },
        'WEP (256-bit)': {
            'pass-length': 29,
            'alpha-lower': true,
            'alpha-upper': true,
            'numbers': true,
            'symbols': true,
            'spaces': true,
            'similar': true
        },
        'WPA-PSK': {
            'pass-length': 63,
            'alpha-lower': true,
            'alpha-upper': true,
            'numbers': true,
            'symbols': true,
            'spaces': true,
            'similar': true
        }
    };

    // Populate select field with all defined presets
    $.each(presets, function(key) {
        $('.template').append('<option value="'+key+'">'+key+'</option>');
    });

    // Function to generate passwords
    function generatePassword() {
        // Set requirements based on page input values
        var requirements = {};
        requirements['pass-length'] = $('#password-generator .pass-length').val();
        requirements['alpha-lower'] = $('#password-generator .alpha-lower').is(':checked') ? true : false;
        requirements['alpha-upper'] = $('#password-generator .alpha-upper').is(':checked') ? true : false;
        requirements['numbers']     = $('#password-generator .numbers').is(':checked') ? true : false;
        requirements['symbols']     = $('#password-generator .symbols').is(':checked') ? true : false;
        requirements['spaces']      = $('#password-generator .spaces').is(':checked') ? true : false;
        requirements['similar']     = $('#password-generator .similar').is(':checked') ? true : false;

        // Build pool of valid characters
        var characterPool = '';
        if (requirements['alpha-lower'])
            characterPool += alphaLower;
        if (requirements['alpha-upper'])
            characterPool += alphaUpper;
        if (requirements['numbers'])
            characterPool += numbers;
        if (requirements['symbols'])
            characterPool += symbols;
        if (requirements['spaces'])
            characterPool += spaces;
        if (!requirements['similar'])
            characterPool = characterPool.replace(/[0O1IlB8\|]/g,'');
        
        // Generate and return password
        var password = '';
        for (var i = 0; i < requirements['pass-length']; i++)
            password += characterPool.charAt(Math.floor(Math.random() * characterPool.length));

        return password;
    }

    // On form submission, validate inputs and generate password
    $('#password-generator form').on('submit', function() {
        // Return if password requested is too long or short
        if ($('.pass-length').val() < 4 || $('.pass-length').val() > 256) {
            displayError('Invalid length. Please select a length between 4 and 256.', '#password-generator');
            return false;
        }

        // Generate password and place in the output textarea
        $('.password-output').text(generatePassword()).select();

        // Prevent default form submission
        return false;
    });

    // Set template to custom when any change is made
    $('#password-generator').on('change', 'input', function() {
        $('.template').val('custom');
    });

    // Load presets when selecting a non-custom template
    $('#password-generator').on('change', '.template', function() {
        // Get name of requested template
        var template = $(this).val();
        
        // Return if using a custom template
        if (template == 'custom')
            return;

        // Loop through template object and fill out form based on values
        $.each(presets[template], function(key, value) {
            if (typeof value === 'boolean')
                $('#password-generator .' + key).prop('checked', value);
            else
                $('#password-generator .' + key).val(value);
        });
    });
});
              
            
!
999px

Console