• Home
  • Shell
    • Emacs
    • Perl
    • screen
    • sed
  • Ubuntu
    • VNC
  • Web Development
    • Javascript
    • Joomla
    • MySQL
    • osTicket
  • Windows
    • Gimp

Web Dev> Validate Password creation with PHP

Dec06
2011
Written by Scott Rowley

The following can be used to test for different criteria in passwords.

<?php
$min = 6;
$max = 20;
$password = $_POST['password'];
$confirmpw = $_POST['confirmpw'];
if($password != $confirmpw){
$error .= "Password and Confirm password do not match! <br />";
}
if( strlen($password) < $min ) {
$error .= "Password too short! <br />";
}
if( strlen($password) > $max ) {
$error .= "Password too long! <br />";
}
if( !preg_match("#[0-9]+#", $password) ) {
$error .= "Password must include at least one number! <br />";
}
if( !preg_match("#[a-z]+#", $password) ) {
$error .= "Password must include at least one letter! <br />";
}
if( !preg_match("#[A-Z]+#", $password) ) {
$error .= "Password must include at least one CAPITAL! <br />";
}
if( !preg_match("#\W+#", $password) ) {
$error .= "Password must include at least one symbol! <br />";
}
if($error){
echo "Password Failure: $error";
} else {
// Code to execute on success.
}
?>
Posted in PHP, Security, Web Development - Tagged check, confirm, password, php, secure, security, validate, validation, verify
« vmWare> Boot to fullscreen VM after host boots.
» Web Dev> Populate PHP/HTML table from MySQL database

Corrections? Questions? Comments?

Find an error?
Everything work out great for you?
Have some feedback?
Like to see something added to the article?

PLEASE leave us a comment after the article and let us know how we are doing, or if something needs corrected, improved or clarified.

Thank you!
- The Management

Advertisement

Sudo Bash
By Geeks - For Geeks

Back to Top