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