zoukankan      html  css  js  c++  java
  • AUTH 用户管理操作

    AUTH的实现是用抽象类来实现的,一个类,对应多种不同的验证方式。

    先来介绍一个抽象类,很有借鉴意义:

    实现一个猴子类,狗类,以及后面可其他类。 通常可以用抽象类和接口实现:

    但是我们不直接定义具体的类,我们把所有猴子类,狗类的特征放在不同的config里面,同过抽象类方法来 初始话一个对象。

    config.php

    1 <?php
    2 return array(
    3     'driver'=>'monkey',//调用那个类。
    4         'index'=>'Ani',//其他。
    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 <?php
    2 // require '../animal.php';
    3 class Ani_dog extends Animal{
    4     
    5     function getname(){
    6         return "dog";
    7     }
    8     
    9 }
    View Code

    monkey.php

    1 <?php
    2 // require '../animal.php';
    3 class Ani_monkey extends Animal{
    4     
    5     function getname(){
    6         return "monkey";
    7     }
    8     
    9 }
    View Code

    Auth也是通过这样的方式来调整认证方式,他有一个自定义 driver为 File的类。

    用着个模块第一步,配置好正确的config。

    调用抽象类的来初始化一个对象;

    进行认证。

    如:

    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实现的有:

    密码加密:

    利用hash_hmac函数进行hash加密存储。

    session记录登录,可定义自动保留时长。到时间未操作自动推出。

  • 相关阅读:
    okhttp进行网络传输文件
    bazel、tensorflow_serving、opencv编译问题
    Linux下设置和查看环境变量(转)
    std::move的实际工作过程
    虚拷贝
    移动构造函数和移动赋值
    while(cin>>word)时的结束方法
    转:windows下命令行工具
    eclipse大括号高亮显示---颜色很淡,改为显眼的颜色
    转: Eclipse 分屏显示同一个文件
  • 原文地址:https://www.cnblogs.com/canbefree/p/3835835.html
Copyright © 2011-2022 走看看