diff options
author | RossTheRoss <mstrapp@protonmail.com> | 2021-02-26 17:22:49 -0600 |
---|---|---|
committer | RossTheRoss <mstrapp@protonmail.com> | 2021-02-26 17:22:49 -0600 |
commit | a7a2c5216530e1c16146be5c840f8baf0cfd01ba (patch) | |
tree | 9244872856116bbe0c05468a24a5bd5735581059 /csci4131/hw3/strap012/passwordcheck.js | |
parent | finish (diff) | |
download | homework-a7a2c5216530e1c16146be5c840f8baf0cfd01ba.tar homework-a7a2c5216530e1c16146be5c840f8baf0cfd01ba.tar.gz homework-a7a2c5216530e1c16146be5c840f8baf0cfd01ba.tar.bz2 homework-a7a2c5216530e1c16146be5c840f8baf0cfd01ba.tar.lz homework-a7a2c5216530e1c16146be5c840f8baf0cfd01ba.tar.xz homework-a7a2c5216530e1c16146be5c840f8baf0cfd01ba.tar.zst homework-a7a2c5216530e1c16146be5c840f8baf0cfd01ba.zip |
e
Diffstat (limited to 'csci4131/hw3/strap012/passwordcheck.js')
-rw-r--r-- | csci4131/hw3/strap012/passwordcheck.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/csci4131/hw3/strap012/passwordcheck.js b/csci4131/hw3/strap012/passwordcheck.js new file mode 100644 index 0000000..97a2918 --- /dev/null +++ b/csci4131/hw3/strap012/passwordcheck.js @@ -0,0 +1,42 @@ +var input; +var result = document.querySelector("span"); +window.addEventListener('DOMContentLoaded', (event) => { + input = document.getElementsByName("password")[0]; +}); +function checkStrength() { + var password = input.value; + var strength = 0; + if (password.length < 6) { + result.removeAttribute("class"); + result.classList.add('short'); + result.innerHTML = "Too short"; + return; + } + if (password.length > 7) { strength += 1;} + // If password contains both lower and uppercase characters, increase strength value. + if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) { strength += 1;} + // If it has numbers and characters, increase strength value. + if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) { strength += 1;} + // If it has one special character, increase strength value. + if (password.match(/([!,%,&,@,#,$,^,*,?,_,~])/)) { strength += 1;} + // If it has two special characters, increase strength value. + if (password.match(/(.*[!,%,&,@,#,$,^,*,?,_,~].*[!,%,&,@,#,$,^,*,?,_,~])/)) { strength += 1;} + // Calculated strength value, we can return messages + // If value is less than 2 + if (strength < 2) { + result.removeAttribute("class"); + result.classList.add('weak'); + result.innerHTML = 'Weak'; + return; + } else if (strength == 2) { + result.removeAttribute("class"); + result.classList.add('good'); + result.innerHTML = 'Good'; + return; + } else { + result.removeAttribute("class"); + result.classList.add('strong'); + result.innerHTML = 'Strong'; + return; + } +} |