Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to allow unlimited password attempts in javascript

var password;
    var pass1="administrator";
    password=prompt('Please enter password',' ');
    if (password!=pass1)
        alert('password is not currect');

    else
        {
            window.location="home.html";
        }

I want to make the number of attempts on the password unlimited

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If you want to keep prompting until they get it, you can use a do…while

var password;
var pass1 = "administrator";
do {
  password = prompt('Please enter password', '');
  if (!password) break
  if (password === pass1) {
    window.location = "home.html";
    break; // stop
  } 
  alert('password is not correct');
} while (password != pass1)

If you just want them to be allowed to reload and try again

var password;
var pass1 = "administrator";
password = prompt('Please enter password', ' ');
if (password != pass1)
  alert('password is not correct');
else {
  window.location = "home.html";
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading