Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Passwords, if weak, can be easy to guess or crack. That is why most secure syste

ID: 3748446 • Letter: P

Question

Passwords, if weak, can be easy to guess or crack. That is why most secure systems force users to choose passwords that are hard to guess. You are asked to write a password verifier that enforces the following rules: - The password should be at least 8 characters long. - The password should at least have one uppercase and one lowercase. - The password should have at least one special character. - The password should have at least one digit. The following requirements should be also implemented: - Your program should allow the user to enter a password of any length/character list, and then verify that these criteria are met. - If password criteria are met, the program should indicate that the password is valid. Otherwise, it should tell the users what are ALL the rules that the chosen password fails to adhere to. - In case the entered password is wrong, the program should not exit, but rather give the user the chance to enter a new password to be verified.

Explanation / Answer

You can use javascript for password validation. so simple javascript password validation code using regex:

<script type="text/javascript">

function checkForm(form)

{

if(form.pwd1.value != "" && form.pwd1.value == form.pwd2.value)

{

if(form.pwd1.value.length < 8)

{

alert("Error: Password must contain at least eight characters!");

form.pwd1.focus();

return false;

}

re = /[0-9]/;

if(!re.test(form.pwd1.value))

{

alert("Error: password must contain at least one number (0-9)!");

form.pwd1.focus();

return false;

}

re = /[a-z]/;

if(!re.test(form.pwd1.value))

{

alert("Error: password must contain at least one lowercase letter (a-z)!");

form.pwd1.focus();

return false;

}

re = /[A-Z]/;

if(!re.test(form.pwd1.value))

{

alert("Error: password must contain at least one uppercase letter (A-Z)!");

form.pwd1.focus();

return false;

}

re=/!@#$%^&*/

if(!re.test(form.pwd1.value))

{

alert("Error: password must contain at least one special character (!@#$%^&*)!");

form.pwd1.focus();

return false;

}

}

else

{

alert("Error: Please check that you've entered and confirmed your password!");

form.pwd1.focus();

return false;

}

alert("You entered a valid password: " + form.pwd1.value);

return true;

}

</script>

<form ...password" name="pwd1"></p></form>