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

283
Visualizações
How to save multiple username and password in javascript

First - I know not to keep passwords and logins that way. I am only doing this as a task.

So, i need to save username and password from register form, and next use it in login form. How i can do this with only html and JS?

Now i have something like that:

let user_name = document.getElementById("username");
let user_paswrd = document.getElementById("password");


let store_data = () => {
  let input_username = localStorage.setItem("username", user_name.value);
  let input_password = localStorage.setItem("password", user_paswrd.value);

};

https://jsfiddle.net/gcu78z20/

it's saving username and password in localstorage, but I need to save all registered username and password. Then in login menu get it back when login. How can I do it? It is better to do this with localstore or cookie?

IMPORTANT INFORMATION this form will only be opened locally. The website will not be on the web.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can store the data as an array.

if(!localStorage.getItem("credentials")) localStorage.setItem("credentials", JSON.stringify([]));

var arr = JSON.parse(localStorage.getItem("credentials"));
console.log(arr)

let user_name = document.getElementById("username");
let user_paswrd = document.getElementById("password");

let store_data = () => {
  credentials.push({username: user_name, password: user_paswrd});
  localStorage.setItem("credentials", JSON.stringify(arr))

};
<input id="username" type='text' placeholder="username"><br>
<input id="password" type='password' placeholder="password"><br>
<button onclick="store_data">Submit</button>

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