Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

Auto Save

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

              
                <body>
  <div class="auth-card">
    <div class="form">
      <p id="alert"></p>
      <form action="https://formspree.io/f/xvolaoaz" method="POST" name="signupForm" id="signupForm">
        <label for="fname">First name <span class="star">*</span>:</label>
        <input id="fn" name="fname" placeholder="e.g Jane" type="text" required>
        <label for="lname">Last name<span class="star">*</span>:</label>
        <input id="ln" name="lname" placeholder="e.g. Doe" type="text" required>
        <label>Email<span class="star">*</span>:</label>
        <input placeholder="e.g.janedoe@gmail.com" name="email" type="email" id="mail" required>
        <label for="password">Password<span class="star">*</span>:</label>
        <input type="password" name="password" placeholder="enter password or auto-generate password" minlength="8" id="pass" required>
        <button type="button" class="auto" id="gen">Auto-generate password</button>
        <button class="submit" type="submit" id="submit" onclick="return handleSubmit()">Submit</button>
      </form>
      <input type="checkbox" id="checkbox" onclick="pwdToggle()"><label class="showPass">Show Password</label>

    </div>
    <div class="side-pic">
      <img src="https://secure-password-generator.com/wp-content/uploads/2021/08/Password-Generator-Security-Quick-Tips-1.png" alt="security pic">
    </div>
  </div>

  <!-- JavaScript -->
  <script src="./app.js"></script>
</body>
              
            
!

CSS

              
                body {
  margin: 0;
  padding: 0;
  font-family: cursive;
}
.star {
  color: red;
  padding: 0 0.1rem;
  font-size: 1rem;
}
#alert {
  color: red;
  font-size: 0.9rem;
  text-align: center;
  display: none;
}
.auth-card {
  display: flex;
  border: 1px solid #ededed;
  box-shadow: 1px 1px 1px 1px #ededed;
  border-radius: 5rem;
  margin: 5rem;
  padding: 3rem 3rem 3rem 5rem;
  justify-content: space-around;
}

.side-pic img {
  height: 28rem;
  width: 27rem;
}
form label,
form input {
  display: block;
  margin: 1rem 0;
}

form input {
  height: 1.4rem;
  width: 20rem;
  outline: none;
  font-size: 1rem;
  padding: 2px 3px;
}

label {
  font-size: 1.2rem;
}

.auto,
.submit {
  border: none;
  background-color: #1f3c88;
  color: #fff;
  padding: 5px 6px;
  border-radius: 3px;
  display: block;
  margin-bottom: 1rem;
}

.auto:hover {
  cursor: pointer;
  background-color: #2e4c6d;
}

.submit {
  background-color: #ea5c2b;
  text-align: center;
  width: 5rem;
}

.showPass {
  font-size: 1rem;
  padding-left: 3px;
}
#checkbox {
  outline: none;
}

.submit:hover {
  cursor: pointer;
  background-color: #ff7f3f;
}
@media only screen and (max-width: 1026px) {
  .auth-card {
    padding-left: 3rem;
  }

  .side-pic img {
    height: 29rem;
    width: 26rem;
  }
}
@media only screen and (max-width: 980px) {
  .side-pic img {
    height: 29rem;
    width: 21rem;
  }
}

@media only screen and (max-width: 900px) {
  .side-pic {
    display: none;
  }
  #alert {
    color: #fff;
    background-color: #950101;
  }

  form input {
    width: 100%;
    height: 1.6rem;
  }
  .auth-card {
    background-color: #2e4c6d;
    padding: 5rem;
    display: block;
  }
  .auto {
    border: 3px solid white;
    background-color: transparent;
    letter-spacing: 1px;
  }
  .submit,
  .submit:hover {
    border: 3px solid #ea5c2b;
    background-color: transparent;
    letter-spacing: 1px;
    color: #ea5c2b;
  }

  body {
    color: #fff;
  }
}
@media only screen and (max-width: 600px) {
  .auth-card {
    margin: 1rem 2rem;
    padding: 2rem 2rem 2rem 5rem;
  }
  body {
    font-size: 1rem;
  }
  input {
    width: 80%;
    height: 1.4rem;
    font-size: 0.9rem;
  }
  .showPass {
    display: block;
  }
}
@media only screen and (max-width: 420px) {
  .auth-card {
    padding-left: 3rem;
  }
}

              
            
!

JS

              
                const fname = document.getElementById("fn");
const lname = document.getElementById("ln");
const email = document.getElementById("mail");
const pwd = document.getElementById("pass");
const formAlert = document.getElementById("alert");
const gen = document.getElementById("gen");
const form = document.getElementById("submit");

gen.addEventListener("click", getPassword);

function handleSubmit() {
  if (
    pwd.value == "" ||
    fname.value == "" ||
    lname.value == "" ||
    email.value == ""
  ) {
    formAlert.style.display = "block";
    formAlert.innerHTML = "All fields are required";
    return false;
  } else if (validatePassword(pwd.value, fname.value, lname.value) == false) {
    return false;
  }
  return true;
}

function getPassword() {
  pwd.value = generatePassword();
}

/* To toggle password visibility*/
function pwdToggle() {
  if (pwd.type == "text") pwd.type = "password";
  else pwd.type = "text";
}

/* To Generate the password*/
function generatePassword() {
  let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  let symbols = "%!@#$^&*-+=|\\(){}:\"';,?";
  let password = "";

  for (let i = 0; i < 4; i++) {
    let randomNumber = Math.floor(Math.random() * 10);
    let lowerCaseLetter = alphabet.charAt(Math.random() * 26).toLowerCase();
    let upperCaseLetter = alphabet.charAt(Math.random() * 26).toUpperCase();
    let specialChar = symbols.charAt(Math.random() * symbols.length);

    password += randomNumber + lowerCaseLetter + upperCaseLetter + specialChar;
  }
  return shuffle(password);
}

/* To shuffle the password string*/
function shuffle(str) {
  let arr = str.split("");
  let n = arr.length;

  for (let i = 0; i < n; i++) {
    let j = Math.floor(Math.random() * n);

    let temp = arr[i];
    arr[i] = arr[j];
    arr[j] = temp;
  }
  return arr.join("");
}

/* To Validate the password*/
function validatePassword(password, fname, lname) {
  if (password.includes(fname) || password.includes(lname)) {
    formAlert.style.display = "block";
    formAlert.innerHTML = "Password must not include first or last name";
    return false;
  } else if (
    !/\d/.test(password) ||
    !/[a-z]/.test(password) ||
    !/[A-Z]/.test(password) ||
    !/[%!@#$^&*-+=|\\(){}:\"';,?]/.test(password)
  ) {
    formAlert.style.display = "block";
    formAlert.innerHTML =
      "Password must be a mix of letters, numbers, and special symbols";
    return false;
  } else return true;
}

              
            
!
999px

Console