From 1ee8ae89b10e7eb2c95a9c7145581d5051953e42 Mon Sep 17 00:00:00 2001 From: Alex Booker Date: Fri, 14 Aug 2015 16:35:54 +0100 Subject: [PATCH] added simple client-side password generator --- js/passwordGenerator.js | 29 +++++++++++++++++++++++++++++ password.html | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 57 insertions(+), 10 deletions(-) create mode 100644 js/passwordGenerator.js diff --git a/js/passwordGenerator.js b/js/passwordGenerator.js new file mode 100644 index 00000000..da85dcf0 --- /dev/null +++ b/js/passwordGenerator.js @@ -0,0 +1,29 @@ +var passwordGenerator = (function() { + return { + generatePassword: function (options) { + var uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXTZ"; + var lowercase = "abcdefghiklmnopqrstuvwxyz"; + var numbers = "0123456789"; + var punct = ".,-/#!$%^&*;:{}=-_`~()]"; + var candidates = ''; + if (options.includeUppercaseChars) { + candidates += uppercase; + } + if (options.includeLowercaseChars) { + candidates += lowercase; + } + if (options.includeNumbers) { + candidates += numbers; + } + if (options.includePunctuationChars) { + candidates += punct; + } + var result = ""; + for (var i = 0; i < options.passwordLength; i++) { + var randomNum = Math.floor(Math.random() * candidates.length); + result += candidates.substring(randomNum, randomNum + 1); + } + return result; + } + }; +})(); diff --git a/password.html b/password.html index 6d4ddbe2..757a8043 100644 --- a/password.html +++ b/password.html @@ -30,31 +30,31 @@
- +
- +
@@ -65,10 +65,28 @@ +