Skip to main content

Q.8:-Verification of valid Password

//Verification of Valid Password 

  1.  <html>  
  2. <head>  
  3. <title> Verification of Valid Password </title>  
  4. </head>  
  5. <script>  
  6. function verifyPassword() {  
  7.   var pw = document.getElementById("pswd").value;  
  8.   var cpw = document.getElementById("cpswd").value;
  9.   //check empty password field  
  10.   if(pw == "") {  
  11.      document.getElementById("message").innerHTML = "**Field Should Not Be Empty!";  
  12.      return false;  
  13.   } 
  14.     if(cpw == "") {  
  15.      document.getElementById("message").innerHTML = "**Field Should Not Be Empty!";  
  16.      return false;  
  17.   }  
  18.     if (pw == cpw) 
  19.     {
  20.       alert("Password is Correct..!!");  
  21.     }
  22.    else {  
  23.      alert("Password is Wrong..!!");  
  24.   }  
  25.    
  26.  //minimum password length validation  
  27.   if(pw.length < 8) {  
  28.      document.getElementById("message").innerHTML = "**Password length must be atleast 8 characters";  
  29.      return false;  
  30.   }   
  31. }  
  32. </script>  
  33.   
  34. <body>  
  35. <center>  
  36. <h1 style="color:green">Verify Valid Password</h1>   
  37.   
  38. <form onsubmit ="return verifyPassword()">  
  39. <!-- Enter Password -->  
  40. <td> Enter Password </td>  
  41. <input type = "password" id = "pswd" value = ""><br><br>
  42. <span id = "message" style="color:red"> </span> <br>
  43. <td> Enter Confirmed Password </td>  
  44. <input type = "password" id = "cpswd" value = "">   
  45. <span id = "message" style="color:red"> </span> <br><br>  
  46.   
  47. <!-- Click to verify valid password -->  
  48. <input type = "submit" value = "Submit">  
  49.   
  50. <!-- Click to reset fields -->  
  51. <button type = "reset" value = "Reset" >Reset</button>  
  52. </form>  
  53. </center>  
  54. </body>  
  55. </html>  


👉Execute👈