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="es">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <meta name="description" content="Generación de contraseñas seguras">
  <meta name="author" content="Gonzalo Chacaltana">
  <title>Generación de contraseñas seguras</title>
  <link href="https://getbootstrap.com/docs/4.4/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous" />
  <meta name="theme-color" content="#563d7c" />
</head>
<body class="bg-light">
  <div class="container">
    <div class="py-5 text-center">
      <h2>Generar Contraseñas Seguras</h2>
      <p class="lead">
        En este sitio web puedes crear contraseñas aleatorias seguras para tus aplicaciones.
      </p>
    </div>
    <div class="row">
      <div class="col-md-4 order-md-2 mb-4">
        <h4 class="d-flex justify-content-between align-items-center mb-3">
          <span class="text-muted">Contraseñas Seguras</span>
          <span id="span_pass_number" class="badge badge-secondary badge-pill">0</span>
        </h4>
        <ul id="ul_passwords" class="list-group mb-3">
        </ul>
      </div>
      <div class="col-md-8 order-md-1">
        <h4 class="mb-3">Configuración</h4>
        <form id="frmSecurePass" class="needs-validation">
          <hr class="mb-4">
          <div class="custom-control custom-checkbox">
            <input type="checkbox" class="custom-control-input" id="chk_uppercase" checked="true">
            <label class="custom-control-label" for="chk_uppercase">Utilizar letras mayúsculas</label>
          </div>
          <div class="custom-control custom-checkbox">
            <input type="checkbox" class="custom-control-input" id="chk_lowercase" checked="true">
            <label class="custom-control-label" for="chk_lowercase">Utilizar letras minusculas </label>
          </div>
          <div class="custom-control custom-checkbox">
            <input type="checkbox" class="custom-control-input" id="chk_numbers" checked="true">
            <label class="custom-control-label" for="chk_numbers">Utilizar Números </label>
          </div>
          <div class="custom-control custom-checkbox">
            <input type="checkbox" class="custom-control-input" id="chk_symbols" checked="true">
            <label class="custom-control-label" for="chk_symbols">Utilizar simbolos </label>
          </div>
          <hr class="mb-4">
          <div class="row">
            <div class="col-md-6 mb-3">
              <label for="cc-name">Longitud de contraseña</label>
              <input type="number" min="6" max="20" value="8" class="form-control" id="password_length"
                placeholder="Ejem: 10" required>
            </div>
            <div class="col-md-6 mb-3">
              <label for="cc-number">Cantidad de contraseñas</label>
              <input type="number" min="1" value="3" max="15" class="form-control" id="password_count"
                placeholder="Ejem: 10" required>
            </div>
          </div>
          <hr class="mb-4">
          <button id="btnGenerate" class="btn btn-primary btn-lg btn-block" type="submit">Generar contraseñas</button>
        </form>
      </div>
    </div>
    <footer class="my-5 pt-5 text-muted text-center text-small">
      <p class="mb-1">&copy; 2020 <a href="http://itensoft.net/" target="_blank">Itensoft Digital Solutions</a></p>
      <ul class="list-inline">
        <li class="list-inline-item"><a href="http://itensoft.net/politica-de-privacidad" target="_blank">Política de
            Privacidad</a></li>
      </ul>
    </footer>
  </div>
  <script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
    integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
    crossorigin="anonymous"></script>
</body>
</html>
              
            
!

CSS

              
                .container {
  max-width: 960px;
}

.lh-condensed {
  line-height: 1.25;
}
              
            
!

JS

              
                /**
 * @file Script para generar contraseñas seguras.
 * @author Gonzalo Chacaltana <gchacaltanab@outlook.com>
 * @class SecurePassword
 * @version 1.1
*/
const SecurePassword = {
    password_length: 6,
    password_counter: 1,
    allowedValuesString: '',
    allowedValues: {
        uppercase: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
        lowercase: 'abcdefghijklmnopqrstuvwxyz',
        numbers: '0123456789',
        symbols: '!@#$%^&*()_+'
    },
    validateChecked: function(){
        const chkboxes = document.getElementsByClassName("custom-control-input");
        let numberChecks = 0;
        Array.prototype.forEach.call(chkboxes, function(el) {
            if (el.checked) {
                numberChecks+=1;
            }
        });
        if (numberChecks==0) {
            throw new Error("Debe seleccionar al menos una opción de valores permitidos.");
        }
    },
    generate: function () {
        this.validateChecked();    
        this.password_length = parseInt(document.getElementById("password_length").value);
        this.password_counter = parseInt(document.getElementById("password_count").value);
        const ul = document.getElementById('ul_passwords');
        ul.innerHTML = '';
        this.getAllowedValuesString();
        for (let i = 0; i < this.password_counter; i++) {
            let li = document.createElement('li');
            li.className = "list-group-item d-flex justify-content-between lh-condensed";
            li.textContent = this.getPassword();
            ul.appendChild(li);
        }
        document.getElementById("span_pass_number").textContent = this.password_counter;
    },
    getAllowedValuesString: function () {
        if (document.getElementById("chk_uppercase").checked) {
            this.allowedValuesString += this.allowedValues.uppercase;
        }
        if (document.getElementById("chk_lowercase").checked) {
            this.allowedValuesString += this.allowedValues.lowercase;
        }
        if (document.getElementById("chk_numbers").checked) {
            this.allowedValuesString += this.allowedValues.numbers;
        }
        if (document.getElementById("chk_symbols").checked) {
            this.allowedValuesString += this.allowedValues.symbols;
        }
    },
    getPassword: function () {
        let password = '';
        for (let i = 0; i < this.password_length; i++) {
            let random = Math.floor(Math.random() * this.allowedValuesString.length);
            password += this.allowedValuesString[random];
        }
        return password;
    }
};

(function () {
    'use strict'
    window.addEventListener('load', function () {
        const $frm = document.getElementById("frmSecurePass");
        $frm.addEventListener("submit", (e) => {
            e.preventDefault();
            try {
                const oSecurePassword = Object.create(SecurePassword);
                oSecurePassword.generate();
            } catch (err) {
                alert(err.message);
                console.warn(err.message);
            }
        });
    }, false)
}())
              
            
!
999px

Console