kcotter Posted March 1, 2011 Share Posted March 1, 2011 I found this simple password protect code online, and I'm wondering if someone can help me modify it. I need it to accept multiple login/passwords. Right now it accepts "login" and "password" as the login/password... can someone show me how to make it accept "login" & "password" AND "login2" & "password2" please??? I'm thinking to the right person this won't be too hard... thanks for any help!!! <script language="javascript"> function pasuser(form) { if (form.id.value=="login") { if (form.pass.value=="password") { location="http://quickonlinetips.com/" } else { alert("Wrong Password") } } else { alert("Wrong Username") } } </script> <form name="login"> Username: <input name="id" size="6" type="text"><br> Password: <input name="pass" size="6" type="password"><br><br> <input value="Login" onclick="pasuser(this.form)" type="button"> </form> Link to comment https://forums.phpfreaks.com/topic/229202-please-help-with-simple-password-protect/ Share on other sites More sharing options...
Adam Posted March 1, 2011 Share Posted March 1, 2011 JavaScript should never be used for password protection. All a user would have to do is view the source of the page and they have the password. Link to comment https://forums.phpfreaks.com/topic/229202-please-help-with-simple-password-protect/#findComment-1181148 Share on other sites More sharing options...
kcotter Posted March 1, 2011 Author Share Posted March 1, 2011 I realize that. But, I'm not putting credit cards here, just a simple blocker to keep out the average joes... Is it possible to make this accept many alternates? Link to comment https://forums.phpfreaks.com/topic/229202-please-help-with-simple-password-protect/#findComment-1181188 Share on other sites More sharing options...
.josh Posted March 4, 2011 Share Posted March 4, 2011 I strongly advise against doing this, as MrAdam said, you should NEVER do this sort of thing client-side. But I'm not your mother so here you go... <script language="javascript"> function pasuser(form) { var up = { 'user1' : 'pass1', 'user2' : 'pass2', 'user3' : 'pass3', // etc... }; if (typeof(up[form.id.value]) != 'undefined') { if (up[form.id.value] == form.pass.value) { document.location="http://quickonlinetips.com/"; } else { alert("Wrong Password"); } } else { alert("Wrong Username"); } } </script> <form name="login"> Username: <input name="id" size="6" type="text"><br> Password: <input name="pass" size="6" type="password"><br><br> <input value="Login" onclick="pasuser(this.form)" type="button"> </form> Link to comment https://forums.phpfreaks.com/topic/229202-please-help-with-simple-password-protect/#findComment-1183048 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.