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 @@ +