MCPcopy Index your code
hub / github.com/RandomAPI/Randomuser.me-Node / genPassword

Method genPassword

api/1.3/api.js:328–380  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

326 }
327
328 genPassword() {
329 if (this.password.length === 0) {
330 return randomItem(this.datasets.common.passwords);
331 }
332
333 let charsets = {
334 special: " !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~",
335 upper: "ABCDEFGHIJKLMNOPQRSTUVWXYZ",
336 lower: "abcdefghijklmnopqrstuvwxyz",
337 number: "0123456789"
338 };
339
340 // Parse sections
341 let sections = ["special", "upper", "lower", "number"];
342 let matches = this.password.split(',').filter(val => sections.indexOf(val) !== -1)
343
344 if (matches.length === 0) {
345 return randomItem(this.datasets.common.passwords);
346 }
347
348 matches = matches.filter((v,i,self) => self.indexOf(v) === i);
349
350 // Construct charset to choose from
351 let charset = "";
352 matches.forEach(match => {
353 charset += charsets[match];
354 });
355
356 let length = this.password.split(',').slice(-1)[0];
357
358 // Range
359 let min, max;
360 if (length.indexOf('-') !== -1) {
361 let range = length.split('-').map(Number);
362 min = Math.min(...range);
363 max = Math.max(...range);
364 } else {
365 min = Number(Number(length));
366 max = min;
367 }
368 min = min > 64 || min < 1 || min === undefined || isNaN(min) ? 8 : min;
369 max = max > 64 || max < 1 || max === undefined || isNaN(max) || max < min ? 64 : max;
370
371 let passLen = range(min, max);
372
373 // Generate password
374 let password = "";
375 for (let i = 0; i < passLen; i++) {
376 password += String(charset[range(0, charset.length-1)]);
377 }
378
379 return password;
380 }
381
382 fullNatName(nat) {
383 let mapping = {

Callers 1

generateMethod · 0.95

Calls 2

randomItemFunction · 0.70
rangeFunction · 0.70

Tested by

no test coverage detected