當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Credentials::validate方法代碼示例

本文整理匯總了PHP中Credentials::validate方法的典型用法代碼示例。如果您正苦於以下問題:PHP Credentials::validate方法的具體用法?PHP Credentials::validate怎麽用?PHP Credentials::validate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Credentials的用法示例。


在下文中一共展示了Credentials::validate方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: header

    exit;
} else {
    try {
        $req = json_decode($_POST["jsondata"]);
        if (!isset($req->behavior)) {
            //these aren't the droids you're looking for...
            header('HTTP/1.1 404 Not Found');
            exit;
        } else {
            switch ($req->behavior) {
                case "getTokenFromCredentials":
                    $msg = new UATokenMessage();
                    // the constructor for Credentials can do some basic validation (or throw an exception)
                    $credentials = new Credentials($req->credentials->username, $req->credentials->password);
                    // the validate() method returns true if valid or false if invalid
                    if ($credentials->validate($token)) {
                        // the $token parameter was passed by reference and set inside validate()
                        $msg->token = $token;
                        //get the current time
                        $dt = new DateTime(null, new DateTimeZone("America/Los_Angeles"));
                        //expire the token in 10 seconds, this should probably reside inside validate
                        $dt->modify("+10 seconds");
                        $msg->expires = $dt->format(DateTime::RFC822);
                        //just some helpful status information for the caller
                        $msg->statuscode = 0;
                        $msg->statusdesc = "Login successful";
                    } else {
                        //bad credentials
                        $msg->statuscode = 1;
                        $msg->statusdesc = "Invalid user name or password";
                    }
開發者ID:nordquip,項目名稱:sousms,代碼行數:31,代碼來源:ua.php

示例2: switch

     // add an element to the statusdesc array
     $msg->statusdesc[] = "Validation Failure: " . $e->getMessage();
     // add another element
     $msg->statusdesc[] = $myConn->getDebug();
 }
 switch ($req->behavior) {
     case "getTokenFromCredentials":
         // the constructor for Credentials can do some basic validation
         // (or throw an exception)
         $credentials = new Credentials($req->credentials->username, $req->credentials->password);
         $token = null;
         $expires = null;
         // the validate() method returns true if valid or false
         // token, expires, and msg->statusdesc are all passed
         // by reference and set inside validate()
         if (!$credentials->validate($myConn->getConn(), $token, $expires, $msg->statusdesc)) {
             // captures the reason for failure
             $msg->statuscode = 1;
             // failed
         } else {
             // success
             // set values in the return message
             $msg->success = true;
             $msg->statuscode = 0;
             $msg->statusdesc = "Login successful";
             // put the token and expires time in the return message
             $msg->retval = array("token" => $token, "expires" => $expires);
         }
         break;
     case "passwordRecovery":
         $passwordRecover = new PasswordRecover($req->passwordRecover->username, $req->passwordRecover->password);
開發者ID:nordquip,項目名稱:sousms,代碼行數:31,代碼來源:ua.php


注:本文中的Credentials::validate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。