Skip to content

Instantly share code, notes, and snippets.

@somefunAgba
Created June 2, 2018 08:27
Show Gist options
  • Save somefunAgba/d64c7c769adf13c6644f38c877e4d670 to your computer and use it in GitHub Desktop.
Save somefunAgba/d64c7c769adf13c6644f38c877e4d670 to your computer and use it in GitHub Desktop.
Password Meter
<html lang="en-us">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="index.css">
<link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet'>
<title>Password Validator</title>
</head>
<body>
<script src="passwordValidator.js"></script>
<div>
<div>
<h3>Password</h3>
<input id="passType" type="text" onkeyup="validatePassword()"
onblur="validatePassword()" /><br/>
<button onclick="validatePassword()" class="button">Validate</button>
</div>
<div id="dispDiv">
<p class="dispLevel">Password Strength: <p id="passwdLevel"></p></p>
<div id="passMeter" class="center">
<div id="meter">
</div>
</div>
<p id="errDisp"></p><br/>
</div>
</div>
</body>
</html>

Password Meter

A simple, minimal and intuitive Password Meter interface for website users to validate, say something like a password. Tools: HTML, CSS, JS

A Pen by Oluwasegun on CodePen.

License.

function validatePassword() {
let passwd = document.getElementById('passType');
document.getElementById('errDisp').innerHTML = "";
let passMeter = document.getElementById('meter');
let validity = 0;
// Check 1
if (passwd.value.toUpperCase() !== passwd.value) {
validity += 0.25;
}
// Check 2
if (passwd.value.toLowerCase()!==passwd.value) {
validity += 0.25;
}
// Check 3
if (/[0-9]/.test(passwd.value)) {
validity += 0.25;
}
// Check 4
if (/[!@#\$%\^&\*]/.test(passwd.value)) {
validity += 0.25;
}
document.getElementById("passwdLevel").innerHTML = (validity*100).toString() + " %";
// Check 5
if (passwd.value.length < 6) {
document.getElementById('errDisp').innerHTML = "Minimum Password Length is 6";
// should be passed to the div for display on screen
}
// Check 6
if (/[\s\S*]{13,}/.test(passwd.value)) {
document.getElementById('errDisp').innerHTML = "Maximum Password Length is 13";
// should be passed to the div for display on screen
}
// set password meter based on validity score
if (validity === 0.25) {
passMeter.style.width = "200px";
passMeter.style.backgroundColor = "red";
passMeter.style.width = "50px";
passMeter.style.transitionProperty = "background-color";
}
else if (validity === 0.50) {
passMeter.style.backgroundColor = "yellow";
passMeter.style.width = "100px";
passMeter.style.transitionProperty = "width";
}
else if (validity === 0.75) {
passMeter.style.backgroundColor = "orange";
passMeter.style.width = "150px";
}
else if (validity === 1.00) {
passMeter.style.backgroundColor = "green";
passMeter.style.width = "200px";
}
else if(validity === 0) {
passMeter.style.backgroundColor = "whitesmoke";
passMeter.style.width = "0px";
passMeter.style.transitionProperty = "background-color";
}
}
/*
console.log(validatePassword('abc'));*/
body{
text-align: center;
font-family: 'Roboto', Arial,Helvetica,sans-serif;
font-size: 2rem;
}
h3{
color: silver;
margin-left: 20px;
}
#dispDiv{
font-size: small;
margin: 10px;
align-content: center;
}
#errDisp{
margin: 10px;
color: crimson;
font-size: small;
}
#passwdLevel{
color: green;
font-size: small;
}
#passType{
font-size: 2rem;
}
.button{
opacity: 0.8;
color: grey;
padding:14px 40px;
margin: 4px 2px;
cursor: pointer;
border: 2px solid #555555;
}
.dispLevel{
margin-top: 10px;
background-blend-mode: multiply;
font-size: small;
color: gray;
text-align: center;
}
#passMeter{
border: 20px gray ;
background-color: whitesmoke;
width: 200px; /*200px;*/
height: 2px; /*5px;*/
}
.center {
margin-left: auto;
margin-right: auto;
overflow: auto;
/*width: 50%;*/
}
#meter{
background-color: whitesmoke;
width: 200px; /*200px;*/
height: 2px; /*5px;*/
transition-property: background-color;
transition-timing-function: ease-in;
transition-duration: 1s;
transition-delay: 0s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment