Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

389
Visualizações
I want to implement a password generator, but so that all options are written to a file

I want to implement a password generator, but so that all options are written to a file (for example, from the numbers "0123456789" and the password length is 3) But the file write does not work for me and does not output only with a length of 3

function genPassword(){
    var possible = "0123456789".split(''),
    length = 3,
    i = 0,
    j = 0,
    step,
    comb;
    while(i<possible.length){
       step = possible[i];
       i++;
       while(j<possible.length){
        comb  = step + '' + possible.slice(j, j + (length -1)).join('');
        j++;
       return comb;
        
       }
       j=0;
       } 
   }  
 
const m = genPassword();
const fs = require("fs");
fs.writeFile('./text.json', JSON.stringify(m), (err) => {
    if (err) console.log(err);
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If you want all possible passwords of a given length created from a given set of characters, you should loop through the array of characters each time picking one and then repeat that operation for each of the picked char till you have the requested number of characters for the password.

function genPassword() {
  var chars = "0123456789".split('');
  var passLen = 3;
  var stack = [""];
  var out = [];
  while (stack.length) {
    var curPass = stack.shift();
    var arr = curPass.length < passLen - 1 ? stack : out;
    for (let idx = 0; idx < chars.length; idx++) {
      arr.push(curPass + chars[idx]);
    }
  }
  return out;
}

console.log(genPassword());

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda