1

I know this method is not safe, but I'm only using it with a couple of friends, I'm using JS to validate a User and Password to redirect to another page, and it works with 1 User, but I don't know how to add another user, the code is this:

<div class="login-page">
  <div class="form">
    <form name="login" class="login-form">
      <input name="userid" type="text" placeholder="Usuario"/>
      <input name="pswrd" type="password" placeholder="Contraseña"/>
      <input id="button" onClick="check(this.form)" value="Login"/>
    </form>
  </div>
</div>
        <script language="javascript">
            function check(form) {
                if(form.userid.value == "USER1" && form.pswrd.value == "PASSWORD1") {
                    location.href = "Inicio";
                }
                else {
                    alert("El usuario o la contraseña son incorrectos, intente nuevamente")
                }
            }
        </script>

Thanks in advance

1 Answer 1

2

You can use || to represent OR, e.g.

if( (form.userid.value == "USER1" && form.pswrd.value == "PASSWORD1") || (form.userid.value == "USER2" && form.pswrd.value == "PASSWORD2") ) {
Sign up to request clarification or add additional context in comments.

2 Comments

Works, is easy and simple, but not elegant :)
Yeah!! that worked!! I tried that before, but i guess i moved something and didn't work before, but now it does :) Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.