aboutsummaryrefslogtreecommitdiffstats
path: root/csci4131/hw2/strap012/passwordcheck.js
diff options
context:
space:
mode:
authorRossTheRoss <mstrapp@protonmail.com>2021-02-10 16:05:37 -0600
committerRossTheRoss <mstrapp@protonmail.com>2021-02-10 16:05:37 -0600
commit40b7e7f9817b13c8bf644a64da9c40c6e140bc20 (patch)
tree76e093677e13f0322247733c168cf910c598f8ad /csci4131/hw2/strap012/passwordcheck.js
parenta (diff)
downloadhomework-40b7e7f9817b13c8bf644a64da9c40c6e140bc20.tar
homework-40b7e7f9817b13c8bf644a64da9c40c6e140bc20.tar.gz
homework-40b7e7f9817b13c8bf644a64da9c40c6e140bc20.tar.bz2
homework-40b7e7f9817b13c8bf644a64da9c40c6e140bc20.tar.lz
homework-40b7e7f9817b13c8bf644a64da9c40c6e140bc20.tar.xz
homework-40b7e7f9817b13c8bf644a64da9c40c6e140bc20.tar.zst
homework-40b7e7f9817b13c8bf644a64da9c40c6e140bc20.zip
i hate everything
Diffstat (limited to '')
-rw-r--r--csci4131/hw2/strap012/passwordcheck.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/csci4131/hw2/strap012/passwordcheck.js b/csci4131/hw2/strap012/passwordcheck.js
new file mode 100644
index 0000000..53e9b3f
--- /dev/null
+++ b/csci4131/hw2/strap012/passwordcheck.js
@@ -0,0 +1,39 @@
+var input = document.getElementById("password");
+var result = document.querySelector("span");
+// result.onload = function() {setResult()};
+// function setResult() {
+// result = document.querySelector("span");
+// }
+function checkStrength() {
+ var password = document.getElementById("password").value;
+ var strength = 0;
+ if (password.length < 6) {
+ result.removeAttribute("class");
+ result.classList.add('short');
+ result.innerHTML = "Too short";
+ }
+ 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';
+ } else if (strength == 2) {
+ result.removeAttribute("class");
+ result.classList.add('good');
+ result.innerHTML = 'Good';
+ } else {
+ result.removeAttribute("class");
+ result.classList.add('strong');
+ result.innerHTML = 'Strong';
+ }
+}