Hosting Solutions
mobile_logo Table of Contents
seal_frontseal_back

Password Strength Check Script Class OOP Tutorial

This is a PHP class file creation and usage tutorial. Working with class files and objects opens up a wider range of software compartmentalization and helps you avoid instance collisions when many object instances simultaneously access a method or property. Object oriented programming should only be used when you have a practical need to reuse a scripted module, or share a complex scripted module with others in a common usage format. You can give people a few simple usage instructions and your class file to allow them to have all the programming power you provide in the class package. strongpass.php (the class file) <?php class strongpass { public function check($password){ $response = "OK"; if(strlen($password) < 8){ $response = "Password must be at least 8 characters"; } else if(is_numeric($password)){ $response = "Password must contain at least one letter"; } else if(!preg_match('#[0-9]#', $password)){ $response = "Password must contain at least one number"; } /* Additional checks you can accomplish as homework - Make sure there is at least one lowercase letter - Make sure there is at least one uppercase letter - Make sure there is at least one symbol character */ return $response; } } ?> demo.php (file that calls the strongpass class into action) <?php $password = ""; $status = ""; if(isset($_POST["password"])){ $password = $_POST["password"]; include_once("strongpass.php"); $strongpass = new strongpass(); $response = $strongpass->check($password); if($response != "OK"){ $status = $response; } else { $status = "Password is strong so parsing can continue here."; } } ?> <h2>Class strongpass Demo</h2> <form action="demo.php" method="post"> <input name="password" type="password" value="<?php echo $password; ?>"> <input type="submit" value="Check Password Strength"> </form> <h3><?php echo $status; ?></h3>
thumb

PHP Videos

Object Oriented Programming

Class File Creation Tutorial Learn PHP OOPClass Properties and Methods Object Oriented ProgrammingConvert MySQL Timestamp to Ago Time Format OOP TutorialUsing the property_exists FunctionUsing the method_exists FunctionUsing the get_parent_class functionUsing the get_object_vars FunctionUsing the get_declared_classes FunctionUsing the get_class FunctionUsing the get_class_vars FunctionUsing the get_class_methods FunctionUsing the class_exists FunctionPassword Strength Check Script Class OOP TutorialExtend Class Object Oriented Programming OOP