当前位置: 首页>>代码示例>>PHP>>正文


PHP Lib::generateHash方法代码示例

本文整理汇总了PHP中Lib::generateHash方法的典型用法代码示例。如果您正苦于以下问题:PHP Lib::generateHash方法的具体用法?PHP Lib::generateHash怎么用?PHP Lib::generateHash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Lib的用法示例。


在下文中一共展示了Lib::generateHash方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: authenticate

 public function authenticate()
 {
     $keys = array('gid', 'token');
     if (!Req::haspost($keys)) {
         return $this->fail('Insufficient data.');
     }
     $gid = Req::post('gid');
     $token = Req::post('token');
     $curl = curl_init('https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=' . $token);
     curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPGET => true));
     $result = curl_exec($curl);
     curl_close($curl);
     $data = json_decode($result);
     // Check aud
     $audSegments = explode('.', $data->aud);
     if (array_shift($audSegments) !== Config::$googleClientId) {
         return $this->fail('Hmmm. Trying to hack?');
     }
     // Check gid
     if ($gid !== $data->sub) {
         return $this->fail('You are not who you say you are!');
     }
     // Check exp
     if (date_create()->format('U') > $data->exp) {
         return $this->fail('Your session has expired. Try again.');
     }
     // Check allowed domain
     if (!empty(Config::$googleAllowedDomain)) {
         if (empty($data->hd)) {
             return $this->fail('Please sign in with your Compass email.');
         }
         $allowedDomain = Config::$googleAllowedDomain;
         if (is_string(Config::$googleAllowedDomain)) {
             $allowedDomain = [Config::$googleAllowedDomain];
         }
         if (!in_array($data->hd, $allowedDomain)) {
             return $this->fail('Please sign in with your Compass email.');
         }
     }
     $user = Lib::table('user');
     $user->load(array('email' => $data->email));
     $user->gid = $data->sub;
     $user->picture = !empty($data->picture) ? $data->picture : '';
     $user->name = $data->name;
     $user->email = $data->email;
     $user->identifier = Lib::generateHash();
     if (empty($user->nick)) {
         $nick = explode('@', $data->email);
         $user->nick = $nick[0];
     }
     $user->store();
     Lib::cookie(Lib::hash(Config::$userkey), $user->identifier);
     return $this->success();
 }
开发者ID:jasonrey,项目名称:project-test-report,代码行数:54,代码来源:user.php

示例2: generateHash

 private function generateHash($length = 64)
 {
     return Lib::generateHash($length);
 }
开发者ID:jasonrey,项目名称:project-test-report,代码行数:4,代码来源:admin.php


注:本文中的Lib::generateHash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。