Auth user management operations

Source: Internet
Author: User

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.

 

 

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.