How to make a login system in Javascript?

后端 未结 3 1463
予麋鹿
予麋鹿 2021-01-25 11:38

I am trying to make a simple login system in javascript. The code should be for multiple users

e.g: user: love pass: cat, user2: mom pass2: love etc.

I need the

3条回答
  •  青春惊慌失措
    2021-01-25 12:14

    Altough it is not advised to make a login system with javascript, it can be done reasonably securely(so the user can't see the passwords directly), you could make like a javascript loader which loads in a bunch of variables from one javascript file, then uses it in the main javascript file and uses encrypted cookies to store the loggedin variables and stuff using essentials.js(A javascript library which makes everything simpler including sessions and cookiestorage) and at last clearing the loader again, then it clears the whole javascript of the page / the javascript connection leaving no trace behind of the password file link.

    This can be done in serveral ways, the esiest and probably the most secure one is something like this.

    
    
    "; if(passwordinput == user1pass) { // This runs when the password and username match up with the variables in the loaded script } else if(passwordinput == user2pass) { //Etc.. } else { console.log("User does not exist"); } document.getElementById("loader").innerHTML = ""; document.getElementById("scripts").innerHTML = "";

    You could even store the passwords in the document itself, that is probably even more secure but more difficult to register new people. I have not tested if this works but I think it will. Also I advise you to only let the passwords.js file reveal itself when a key is given as a get parameter, this is really easy to do and I think you can figure that one out on your own. Also I advise you to hash the passwords to add a thin layer of protection on top of it, this is also really easy to do and I think you'll be able to figure that out by yourself aswell.

    I hope this answer helped some of you visitors of this question with the same question.

提交回复
热议问题