Example #1
0
 function test_simple_auth()
 {
     $verifier = function ($user, $pass) {
         return true;
     };
     $method = function ($callback) {
         return $callback('', '');
     };
     $this->assertTrue(simple_auth($verifier, $method));
 }
Example #2
0
<?php

if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
    header("WWW-Authenticate: Basic realm=\"Secure Page\"");
    header("HTTP\\ 1.1 401 Unauthorized");
    header("Content-Type: application/json");
    echo '{ auth: 0 }';
    exit;
}
if (simple_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
    // Do nothing
} else {
    header("WWW-Authenticate: Basic realm=\"Secure Page\"");
    header("HTTP\\ 1.1 401 Unauthorized");
    header("Content-Type: application/json");
    echo '{ auth: 0 }';
    exit;
}
/********************************************/
function simple_auth($user, $pass)
{
    require_once '../config.php';
    if (htmlentities($user) == htmlentities(API_USER) && htmlentities($pass) == htmlentities(API_PASS)) {
        return 1;
    } else {
        return 0;
    }
}
Example #3
0
function smf_updateMemberData($username, $info)
{
    $api = new SmfRestClient(simple_auth(SMF_SEC_KEY, 'ENCODE'));
    $result = $api->update_memberData($username, $info);
    return $result->data == 'true';
}
Example #4
0
 /**
  * Simplifies authorization down to:
  *
  *     <?php
  *
  *     if (! User::require_login ()) {
  *         // unauthorized
  *     }
  *
  *     ?>
  */
 public static function require_login()
 {
     $class = get_called_class();
     return simple_auth(array($class, 'verifier'), array($class, 'method'));
 }
Example #5
0
 /**
  * Simplifies authorization for admins down to:
  *
  *     <?php
  *     
  *     if (! User::require_admin ()) {
  *         // unauthorized
  *     }
  *     
  *     ?>
  */
 public static function require_admin()
 {
     if (is_object(self::$user)) {
         if (self::$user->session_id == $_SESSION['session_id']) {
             if (self::$user->type == 'admin') {
                 return true;
             }
             return false;
         }
     } else {
         $class = get_called_class();
         $res = simple_auth(array($class, 'verifier'), array($class, 'method'));
         if ($res && self::$user->type == 'admin') {
             return true;
         }
     }
     return false;
 }
Example #6
0
 /**
  * Require authentication via custom callbacks that are passed to `simple_auth()`.
  * If the second callback is missing, the first will be assumed to be an array
  * containing the two callbacks.
  *
  * See `apps/user/lib/Auth` for built-in auth handlers.
  */
 public function require_auth($verifier, $method = false)
 {
     if ($method === false) {
         list($verifier, $method) = $verifier;
     }
     return simple_auth($verifier, $method);
 }