aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarak <[email protected]>2017-02-09 17:22:44 -0500
committerMarak <[email protected]>2017-02-09 17:22:44 -0500
commit02be0dc61e0ff84bdbe975d66b09c6231b25542c (patch)
tree9c025a03ae9eda32ecb8b7b4ccb5892a5fa239d6
parent7e96b93869b422af5a63c115e04ff0206bf7b228 (diff)
downloadfaker-02be0dc61e0ff84bdbe975d66b09c6231b25542c.tar.xz
faker-02be0dc61e0ff84bdbe975d66b09c6231b25542c.zip
[refactor] [fix] Move password generator to core
* Migrates password generator from vendor * Removes erroneous browserifying code * Switches `Math.random` to faker random * Closes #460 * Should close #430
-rw-r--r--lib/internet.js60
-rw-r--r--vendor/password-generator.js65
2 files changed, 51 insertions, 74 deletions
diff --git a/lib/internet.js b/lib/internet.js
index 4b0bfd8a..0de5ef65 100644
--- a/lib/internet.js
+++ b/lib/internet.js
@@ -1,5 +1,4 @@
-var password_generator = require('../vendor/password-generator.js'),
- random_ua = require('../vendor/user-agent');
+var random_ua = require('../vendor/user-agent');
/**
*
@@ -332,13 +331,56 @@ var Internet = function (faker) {
* @param {string} pattern
* @param {string} prefix
*/
- self.password = function (len, memorable, pattern, prefix) {
- len = len || 15;
- if (typeof memorable === "undefined") {
- memorable = false;
- }
- return password_generator(len, memorable, pattern, prefix);
- }
+ self.password = function (len, memorable, pattern, prefix) {
+ len = len || 15;
+ if (typeof memorable === "undefined") {
+ memorable = false;
+ }
+ /*
+ * password-generator ( function )
+ * Copyright(c) 2011-2013 Bermi Ferrer <[email protected]>
+ * MIT Licensed
+ */
+ var consonant, letter, password, vowel;
+ letter = /[a-zA-Z]$/;
+ vowel = /[aeiouAEIOU]$/;
+ consonant = /[bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ]$/;
+ var _password = function (length, memorable, pattern, prefix) {
+ var char, n;
+ if (length == null) {
+ length = 10;
+ }
+ if (memorable == null) {
+ memorable = true;
+ }
+ if (pattern == null) {
+ pattern = /\w/;
+ }
+ if (prefix == null) {
+ prefix = '';
+ }
+ if (prefix.length >= length) {
+ return prefix;
+ }
+ if (memorable) {
+ if (prefix.match(consonant)) {
+ pattern = vowel;
+ } else {
+ pattern = consonant;
+ }
+ }
+ n = faker.random.number(94) + 33;
+ char = String.fromCharCode(n);
+ if (memorable) {
+ char = char.toLowerCase();
+ }
+ if (!char.match(pattern)) {
+ return _password(length, memorable, pattern, prefix);
+ }
+ return _password(length, memorable, pattern, "" + prefix + char);
+ };
+ return _password(len, memorable, pattern, prefix);
+ }
self.password.schema = {
"description": "Generates a random password.",
diff --git a/vendor/password-generator.js b/vendor/password-generator.js
deleted file mode 100644
index 35ca4486..00000000
--- a/vendor/password-generator.js
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * password-generator
- * Copyright(c) 2011-2013 Bermi Ferrer <[email protected]>
- * MIT Licensed
- */
-(function (root) {
-
- var localName, consonant, letter, password, vowel;
- letter = /[a-zA-Z]$/;
- vowel = /[aeiouAEIOU]$/;
- consonant = /[bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ]$/;
-
-
- // Defines the name of the local variable the passwordGenerator library will use
- // this is specially useful if window.passwordGenerator is already being used
- // by your application and you want a different name. For example:
- // // Declare before including the passwordGenerator library
- // var localPasswordGeneratorLibraryName = 'pass';
- localName = root.localPasswordGeneratorLibraryName || "generatePassword",
-
- password = function (length, memorable, pattern, prefix) {
- var char, n;
- if (length == null) {
- length = 10;
- }
- if (memorable == null) {
- memorable = true;
- }
- if (pattern == null) {
- pattern = /\w/;
- }
- if (prefix == null) {
- prefix = '';
- }
- if (prefix.length >= length) {
- return prefix;
- }
- if (memorable) {
- if (prefix.match(consonant)) {
- pattern = vowel;
- } else {
- pattern = consonant;
- }
- }
- n = Math.floor(Math.random() * 94) + 33;
- char = String.fromCharCode(n);
- if (memorable) {
- char = char.toLowerCase();
- }
- if (!char.match(pattern)) {
- return password(length, memorable, pattern, prefix);
- }
- return password(length, memorable, pattern, "" + prefix + char);
- };
-
-
- ((typeof exports !== 'undefined') ? exports : root)[localName] = password;
- if (typeof exports !== 'undefined') {
- if (typeof module !== 'undefined' && module.exports) {
- module.exports = password;
- }
- }
-
- // Establish the root object, `window` in the browser, or `global` on the server.
-}(this)); \ No newline at end of file