Auth is implemented using abstract classes. A Class corresponds to multiple verification methods.
An abstract class is introduced for reference:
Implement a monkey, dog, and other classes. It can usually be implemented using abstract classes and interfaces:
However, we do not directly define a specific class. We put all monkey and dog features in different config, and use the abstract class method to initialize an object.
Config. php
1 <? PhP2 return array (3 'driver '=> 'monkey', // call that class. 4 'index' => 'ani ', // others. 5 );
Config
Animal. php
1 <?php 2 abstract class Animal{ 3 protected static $_instance; 4 5 public static function instance($config){ 6 7 $driver=$config[‘driver‘]; 8 $ind=$config[‘index‘]; 9 require "animal/$driver.php";10 11 $class=$ind."_".$driver;12 self::$_instance=new $class($config);13 return self::$_instance;14 }15 16 }17 18 $config=require ‘animal/config/config.php‘;19 $dog=Animal::instance($config);20 echo $dog->getname();
View code
Dog. php
1 <?php2 // require ‘../animal.php‘;3 class Ani_dog extends Animal{4 5 function getname(){6 return "dog";7 }8 9 }
View code
Monkey. php
1 <?php2 // require ‘../animal.php‘;3 class Ani_monkey extends Animal{4 5 function getname(){6 return "monkey";7 }8 9 }
View code
Auth also adjusts the authentication method in this way. It has a class with a custom driver as file.
Use the first step of the module to configure the correct config.
Calls an abstract class to initialize an object;
For authentication.
For example:
1 $auth = Auth::instance();2 if ($auth->login(‘admin‘, ‘good_pass‘, true)) {3 echo ‘hello, ‘ . $auth->get_user();4 } else {5 echo ‘login failed!‘;6 }7 $auth->logout();
View code
Auth implementation includes:
Password Encryption:
Use the hash_hmac function for hash encrypted storage.
Session Logging logon, which defines the automatic retention period. This feature is automatically released when no operation is performed.