Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

284
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda