Jump to: navigation, search

PHP HTML Password

From w3cyberlearnings

Contents

PHP works with HTML Input for password

HTML input tag with the type password is password input.

Syntax password

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

Example 1

  • strlen() function check the length of the string.
  • In this example, we only allow when the passwords are both matched, and the length of the password have to be at least 8 characters length and not more than 18 characters length.
<?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" autocomplete="off" />
</td>
</tr>
<tr>
<td valign="top">Confirm:</td>
<td>
<input type="password" name="pass2" size="20" maxlength="20" autocomplete="off" />
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" name="Submit" value="Submit" />
</td>
</tr>
</table>
</form>
</body>
</html>

Output

Php form password 1.png


Related Links


  1. HTML POST
  2. HTML GET
  3. HTML Textarea
  1. HTML Hidden Field
  2. HiddenField Multiple Pages
  3. HTML Password
  1. HTML Textbox
  2. HTML Checkbox
  3. HTML Radio
  1. Drop down list
  2. Pass value uses URL
  3. Pass value uses URL 2.
  4. Multiple Submit Buttons
Navigation
Web
SQL
MISC
References