PHP HTML Password

From CoderLearner
Jump to: navigation, search

PHP works with HTML Input for password

Password field is used for password input, and it makes the input characters as a star symbol.

Syntax password

<input type="password" name="password" size="33" maxlength="33" />

Example 1

  • strlen() function check the length of the string.
  • In this example, the password have to be at least 8 characters length and not more than 18 characters length, and the password inputs have to be matched.
<?php
if ($_POST) {
   $pass1 = $_POST['pass1'];
   $pass2 = $_POST['pass2'];
   if ($pass1 == $pass2 && !empty($pass2)
           && strlen($pass1) >= 8 && strlen($pass1) <= 18) {
      $new_password = md5($pass1);
      echo $new_password;
   } else {
      echo 'error';
   }
}
?>
<html>
   <head>
      <title>Password</title>
   </head>
   <body>
      <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
         <table border="0">
            <tr>
               <td>Password:</td>
               <td>
                  <input type="password" name="pass1" size="20" maxlength="20"/>
               </td>
            </tr>
            <tr>
               <td valign="top">Confirm:</td>
               <td>
                  <input type="password" name="pass2" size="20" maxlength="20"/>
               </td>
            </tr>
            <tr>
               <td colspan="2">
                  <input type="submit" name="Submit" value="Submit" />
               </td>
            </tr>
         </table>
      </form>
   </body>
</html>

Try It