简体   繁体   中英

More than one password

Good Day. I'm using a 'pasuser form' as a password protectant for a website page. The script below only allows the use of ONE password and username. Does anyone know how to change the script for multiple password/username use? Basically, I would prefer each user to have his unique password/username. THANK YOU very much for your time and help.

function pasuser(form) {

if (form.id.value != "user") return alert("Invalid UserID");
if (form.pass.value != "pass") return alert("Invalid Password");
location = "http://tempuri.org/";
}

Password protection in the client code is just foolish, but the principle might be useful for something else...

Put the user names and passwords in an array, and loop through the items:

var pass = [
  { user: 'ebby', pwd: 'john3' },
  { user: 'john', pwd: 'kate4' },
  { user: 'kate', pwd: 'ebby1' }
];
// look for a match
var found = false;
for (var i = 0; i < pass.length; i++) {
  if (form.id.value == pass[i].user && form.pass.value == pass[i].pwd) {
    found = true;
    break; // exit from loop
  }
}
// act on the result
if (found) {
  location = "http://tempuri.org/";
} else {
  alert('User name or password is wrong.');
}

Note: It's customary not to tell visitors if the user name is correct or not. The login process should not be possible to use to find out if a specific user exists or not. (Not that it matters when the user names and passwords are clearly visible in the page source, but anyway...)

set cookies and get them during authentication. The client can't view what is inside the cookies. But it will be better to use php.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM