mirror of
https://github.com/privacyguides/privacyguides.org.git
synced 2025-05-13 03:32:39 -04:00
added simple client-side password generator
This commit is contained in:
parent
0cac76a14a
commit
1ee8ae89b1
2 changed files with 57 additions and 10 deletions
29
js/passwordGenerator.js
Normal file
29
js/passwordGenerator.js
Normal file
|
@ -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;
|
||||
}
|
||||
};
|
||||
})();
|
Loading…
Add table
Add a link
Reference in a new issue