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.
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>