В настоящее время, когда вы находитесь на странице, один человек может зарегистрировать одну учетную запись.
Да, я знаю, что так не следует делать. Я просто возился с печеньками. Итак, есть ли способ сделать так, чтобы было несколько учетных записей вместо одной.
function setCookie(cname,cvalue,exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires = " + d.toGMTString();
document.cookie = cname + " = " + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + " = ";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function registerCookie() {
var user = prompt("Please enter your desired username:","");
var pass = prompt("Please enter your desired password:","");
if (user != "" && user != null && pass != "" && pass != null) {
setCookie("username", user, 30);
setCookie("password", pass, 30);
}
}
function loginCookie() {
var user=getCookie("username");
var pass=getCookie("password");
var check=prompt("Username");
var check2=prompt("password");
if (check == user && check2 == pass) {
alert("Welcome back, " + user);
} else {
alert("False information");
}
}
function start() {
var response = prompt("Would you like to register?");
if (response == "yes" || response == "Yes") {
registerCookie();
} else if (response == "no" || response == "No") {
loginCookie();
} else {
alert("We did not understand your input");
}
}<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body onload = "start()">
</body>
</html>


![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Думаю, здесь можно использовать некоторые уловки: используйте имя пользователя в качестве имени файла cookie.
function registerCookie() {
var user = prompt("Please enter your desired username:","");
var pass = prompt("Please enter your desired password:","");
if (user != "" && user != null && pass != "" && pass != null) {
setCookie("username_"+user, user, 30);
setCookie("password_"+user, pass, 30);
}
}
function loginCookie() {
var checkUser=prompt("Username");
var checkPass=prompt("password");
var user=getCookie("username_"+checkUser);
//alert(user)
var pass=getCookie("password_"+checkUser);
//alert(pass)
if (checkUser == user && checkPass == pass) {
alert("Welcome back, " + user);
} else {
alert("False information");
}
}