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


PHP Security::hash方法代码示例

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


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

示例1: testHash

 /**
  * testHash method
  *
  * @return void
  */
 public function testHash()
 {
     $_hashType = Security::$hashType;
     $key = 'someKey';
     $hash = 'someHash';
     $this->assertSame(40, strlen(Security::hash($key, null, false)));
     $this->assertSame(40, strlen(Security::hash($key, 'sha1', false)));
     $this->assertSame(40, strlen(Security::hash($key, null, true)));
     $this->assertSame(40, strlen(Security::hash($key, 'sha1', true)));
     $result = Security::hash($key, null, $hash);
     $this->assertSame($result, 'e38fcb877dccb6a94729a81523851c931a46efb1');
     $result = Security::hash($key, 'sha1', $hash);
     $this->assertSame($result, 'e38fcb877dccb6a94729a81523851c931a46efb1');
     $hashType = 'sha1';
     Security::setHash($hashType);
     $this->assertSame($hashType, Security::$hashType);
     $this->assertSame(40, strlen(Security::hash($key, null, true)));
     $this->assertSame(40, strlen(Security::hash($key, null, false)));
     $this->assertSame(32, strlen(Security::hash($key, 'md5', false)));
     $this->assertSame(32, strlen(Security::hash($key, 'md5', true)));
     $hashType = 'md5';
     Security::setHash($hashType);
     $this->assertSame($hashType, Security::$hashType);
     $this->assertSame(32, strlen(Security::hash($key, null, false)));
     $this->assertSame(32, strlen(Security::hash($key, null, true)));
     $this->assertSame(64, strlen(Security::hash($key, 'sha256', false)));
     $this->assertSame(64, strlen(Security::hash($key, 'sha256', true)));
     Security::setHash($_hashType);
 }
开发者ID:Slayug,项目名称:castor,代码行数:34,代码来源:SecurityTest.php

示例2: login

 /**
  * Index Login method  API URL  /api/login method: POST
  * @return json response
  */
 public function login()
 {
     try {
         $user = $this->Auth->identify();
         if ($user) {
             $user = $this->Users->get($user['id']);
             if (!$user) {
             }
         } else {
             throw new UnauthorizedException("Invalid login");
         }
         // Generate user Auth token
         $authentication = $this->Authentications->newEntity();
         $authentication->auth_token = Security::hash($user->id . $user->email, 'sha1', true);
         $authentication->user_id = $user->id;
         $authentication->ip = $this->request->clientIp();
         $this->Authentications->save($authentication);
         $this->Auth->setUser($user->toArray());
     } catch (UnauthorizedException $e) {
         throw new UnauthorizedException($e->getMessage(), 401);
     }
     $this->set('user', $this->Auth->user());
     $this->set('token', $authentication->auth_token);
     $this->set('_serialize', ['user', 'token']);
 }
开发者ID:vla9isla8,项目名称:hochuna_cakephp,代码行数:29,代码来源:LoginController.php

示例3: setContentsFile

 public function setContentsFile()
 {
     $this->__contentsFileSettings();
     foreach ($this->__contentsFileSettings['fields'] as $field => $field_setting) {
         $file_info = $this->{$field};
         if (!empty($file_info) && array_key_exists('error', $file_info) && $file_info['error'] != UPLOAD_ERR_NO_FILE) {
             $file_set = ['model' => $this->_registryAlias, 'model_id' => $this->id, 'field_name' => $field, 'file_name' => $file_info['name'], 'file_content_type' => $file_info['type'], 'file_size' => $file_info['size'], 'file_error' => $file_info['error']];
             //$file_infoにtmp_nameがいるときはtmpディレクトリへのファイルのコピーを行う
             if (!empty($file_info['tmp_name'])) {
                 $tmp_file_name = Security::hash(rand() . Time::now()->i18nFormat('YYYY/MM/dd HH:ii:ss') . $file_info['name']);
                 if ($this->__getExt($file_info['name']) !== null) {
                     $tmp_file_name .= '.' . $this->__getExt($file_info['name']);
                 }
                 if (!copy($file_info['tmp_name'], $field_setting['cacheTempDir'] . $tmp_file_name)) {
                     //エラー
                 }
                 $file_set['tmp_file_name'] = $tmp_file_name;
             }
             //これを残して次に引き渡したくないので
             unset($this->{$field});
             $this->{'contents_file_' . $field} = $file_set;
         }
     }
     return $this;
 }
开发者ID:satthi,项目名称:contents-file,代码行数:25,代码来源:ContentsFileTrait.php

示例4:

 function ajax_login()
 {
     if ($this->request->is('ajax')) {
         $email = $this->request->data['email'];
         $password = Security::hash($this->request->data['password'], 'sha1', true);
         $user = $this->Users->find()->where(['email' => $email, 'password' => $password, 'status <>' => USER_STATUS_DELETED])->first();
         if ($user) {
             if ($user->status == USER_STATUS_ACTIVE) {
                 $user->auth_token = \Core::randomCode();
                 // if 'remember me' checked, save cookie
                 /*if(isset($this->request->data['User']['remember']))
                   {
                       $this->Cookie->write('CookieRemember', $user->auth_token, null, '30 days');
                   }
                   else
                   {
                       $this->Cookie->delete('CookieRemember');
                   }*/
                 if ($this->Users->save($user)) {
                     $this->request->session()->write('Core.Users', $user);
                     $this->ajax['status'] = AJAX_STATUS_SUCCESS;
                     $this->ajax['redirect'] = $this->request->webroot . 'admin/users/index';
                 }
             } else {
                 $this->ajax['status'] = AJAX_STATUS_ERROR;
                 $this->ajax['error'] = __('your account has been blocked');
             }
         } else {
             $this->ajax['status'] = AJAX_STATUS_ERROR;
             $this->ajax['error'] = __('invalid email or password');
         }
     }
 }
开发者ID:nguyennghiem1205,项目名称:Wss,代码行数:33,代码来源:UsersController.php

示例5: beforeSave

 public function beforeSave(Event $event)
 {
     $entity = $event->data['entity'];
     if ($entity->isNew()) {
         $entity->api_key = Security::hash(Text::uuid());
     }
     return true;
 }
开发者ID:uedatakeshi,项目名称:myApp,代码行数:8,代码来源:UsersTable.php

示例6: hash

 /**
  * Signs the url with a salted hash
  *
  * @throws \RuntimeException
  * @param array $options
  * @return string
  */
 public function hash($options)
 {
     $mediaSalt = Configure::read('Imagine.salt');
     if (empty($mediaSalt)) {
         throw new \RuntimeException(__d('imagine', 'Please configure {0} using {1}', 'Imagine.salt', 'Configure::write(\'Imagine.salt\', \'YOUR-SALT-VALUE\')'));
     }
     ksort($options);
     return urlencode(Security::hash(serialize($options) . $mediaSalt));
 }
开发者ID:nielin,项目名称:cakephp-imagine-plugin,代码行数:16,代码来源:ImagineHelper.php

示例7: initialize

 /**
  * Initialization hook method.
  *
  * Use this method to add common initialization code like loading components.
  *
  * @return void
  */
 public function initialize()
 {
     parent::initialize();
     $this->loadComponent('Auth', ['authenticate' => ['ByuApi', 'CasAuth.Cas' => ['hostname' => 'cas.byu.edu', 'uri' => 'cas']]]);
     $this->loadComponent('AuthUser');
     $this->loadComponent('Flash');
     if ($this->request->query('debug') && !Configure::read('debug')) {
         $user = $this->Auth->user();
         if (!empty($user['roles']['admin'])) {
             $this->loadComponent('Cookie');
             $this->Cookie->configKey('cake_manual_debug', 'encryption', false);
             $this->Cookie->write('cake_manual_debug', $user['username'] . 'debug|' . Security::hash($user['username'] . 'debug'));
         }
     }
 }
开发者ID:byu-oit-appdev,项目名称:byusa-clubs,代码行数:22,代码来源:AppController.php

示例8: index

 /**
  * Attempting to make a password beefer'upper
  */
 public function index()
 {
     if ($this->request->is(['post', 'put', 'patch'])) {
         $userId = $this->request->session()->read('User.id');
         $this->loadModel('Users');
         $user = $this->Users->get($userId);
         $input = $this->request->data['input'];
         $hash1 = Security::hash($input, 'sha512', $user->username);
         $hash2 = Security::hash($hash1, 'sha512', $user->username . $hash1);
         $hash3 = Security::hash($hash2, 'sha512', $hash2 . $hash1);
         $hash4 = Security::hash($hash3, 'sha512', $hash1 . $hash2);
         $hash5 = Security::hash($hash4, 'sha512', $hash2 . $hash3);
         $hash6 = Security::hash($hash5, 'sha512', $hash3 . $hash4);
         $hash7 = Security::hash($hash6, 'sha512', $hash4 . $hash5);
         $output = $hash7;
         $this->set(compact('output'));
     }
 }
开发者ID:Vooders,项目名称:vooders.com,代码行数:21,代码来源:PasswordGeneratorController.php

示例9: main

 /**
  * main() method.
  *
  * @return bool|int Success or error code.
  */
 public function main()
 {
     $members = $this->Passwords->find('list', ['keyField' => 'id', 'valueField' => 'password']);
     if ($members) {
         $members = $members->toArray();
     }
     $allMembers = $this->Members->find('all');
     $count = count($allMembers->toArray());
     $index = 1;
     foreach ($allMembers as $item) {
         if ($members[$item->id]) {
             $password = $members[$item->id];
         } else {
             $password = 'hw12345678';
         }
         $password = Security::hash($password, 'sha1', true);
         $member = $this->Members->patchEntity($item, ['password' => $password], ['validate' => false]);
         $this->Members->save($member);
         $this->out($index . ' / ' . $count);
         $index++;
     }
 }
开发者ID:nguyennghiem1205,项目名称:japan-circle,代码行数:27,代码来源:UpdatePasswordShell.php

示例10: login

 function login()
 {
     $requestData = $this->getRequestData(['email', 'password']);
     $email = $requestData['email'];
     $password = Security::hash($requestData['password'], 'sha1', true);
     $user = $this->Users->find()->where(['email' => $email, 'password' => $password, 'status <>' => USER_STATUS_DELETED])->first();
     if ($user) {
         if ($user->status == USER_STATUS_ACTIVE) {
             $user->auth_token = \Core::randomCode();
             if ($this->Users->save($user)) {
                 $this->Output['status'] = API_STATUS_SUCCESS;
                 $this->Output['token'] = $user->auth_token;
             }
         } else {
             $this->Output['status'] = API_STATUS_ERROR;
             $this->Output['error_code'] = ERROR_EXCEPTION_USER_BLOCK;
         }
     } else {
         $this->Output['status'] = API_STATUS_ERROR;
         $this->Output['error_code'] = ERROR_EXCEPTION_USER_INVALID;
     }
 }
开发者ID:nguyennghiem1205,项目名称:Wss,代码行数:22,代码来源:UsersController.php

示例11: _buildFieldToken

 /**
  * Generate the token data for the provided inputs.
  *
  * @param string $url The URL the form is being submitted to.
  * @param array $fields If set specifies the list of fields to use when
  *    generating the hash.
  * @param array $unlockedFields The list of fields that are excluded from
  *    field validation.
  * @return array The token data.
  */
 protected function _buildFieldToken($url, $fields, $unlockedFields = [])
 {
     $locked = [];
     foreach ($fields as $key => $value) {
         if (is_numeric($value)) {
             $value = (string) $value;
         }
         if (!is_int($key)) {
             $locked[$key] = $value;
             unset($fields[$key]);
         }
     }
     sort($unlockedFields, SORT_STRING);
     sort($fields, SORT_STRING);
     ksort($locked, SORT_STRING);
     $fields += $locked;
     $locked = implode(array_keys($locked), '|');
     $unlocked = implode($unlockedFields, '|');
     $hashParts = [$url, serialize($fields), $unlocked, Security::salt()];
     $fields = Security::hash(implode('', $hashParts), 'sha1');
     return ['fields' => urlencode($fields . ':' . $locked), 'unlocked' => urlencode($unlocked)];
 }
开发者ID:CakeDC,项目名称:cakephp,代码行数:32,代码来源:SecureFieldTokenTrait.php

示例12: index

 /**
  * Index Login method  API URL  /api/login method: POST
  * @return json response
  */
 public function index()
 {
     try {
         if (!isset($this->request->data['username'])) {
             throw new UnauthorizedException("Please enter your username");
         }
         if (!isset($this->request->data['password'])) {
             throw new UnauthorizedException("Please enter your password");
         }
         $username = $this->request->data['username'];
         $password = $this->request->data['password'];
         // Check for user credentials
         $users = TableRegistry::get('Users');
         $user = $users->find()->where(['username' => $username, 'password' => $password])->first();
         //$this->User->find('login', ['username'=>$username, 'password'=>$password]);
         if (!$user) {
             throw new UnauthorizedException("Invalid login");
         }
         // if everything is OK set Auth session with user data
         //debug($token);
         //but first generate and insert token into user before put into Auth
         $token = Security::hash($user->id . $user->username, 'sha1', true);
         //TODO - maybe need tmestamp on this so saving token doesn't work outside current session
         //debug($user);
         $user['token'] = $token;
         $this->Auth->setUser($user->toArray());
         // Generate user Auth token
         // $token =  Security::hash($user->id.$user->username, 'sha1', true);  //TODO - maybe need tmestamp on this so saving token doesn't work outside current session
         // Add user token into Auth session
         $this->request->session()->write('Auth.User.token', $token);
         //add token into
         // return Auth token
         $this->response->header('Authorization', 'Bearer ' . $token);
     } catch (UnauthorizedException $e) {
         throw new UnauthorizedException($e->getMessage(), 401);
     }
     $this->set('user', $this->Auth->user());
     $this->set('_serialize', ['user']);
 }
开发者ID:markwfultz,项目名称:angucake,代码行数:43,代码来源:LoginController.php

示例13: authenticate

 /**
  * {@inheritDoc}
  */
 public function authenticate(Request $request, Response $response)
 {
     $result = parent::authenticate($request, $response);
     if (!$result) {
         // fail? try using "username" as "email"
         $this->_config['fields']['username'] = 'email';
         if (!empty($request->data['username'])) {
             $request->data['email'] = $request->data['username'];
         }
         $result = parent::authenticate($request, $response);
     }
     if ($result && !empty($request->data['remember'])) {
         $controller = $this->_registry->getController();
         if (empty($controller->Cookie)) {
             $controller->loadComponent('Cookie');
         }
         // user information array
         $user = json_encode($result);
         // used to check that user's info array is authentic
         $hash = Security::hash($user, 'sha1', true);
         $controller->Cookie->write('User.Cookie', json_encode(compact('user', 'hash')));
     }
     return $result;
 }
开发者ID:quickapps-plugins,项目名称:user,代码行数:27,代码来源:FormAuthenticate.php

示例14: testIdentify

 /**
  * testIdentify method
  *
  * @return void
  */
 public function testIdentify()
 {
     $AuthLoginFormAuthenticate = $this->getMock('Cake\\Controller\\Component\\Auth\\FormAuthenticate', ['authenticate'], [], '', false);
     $this->Auth->authenticate = ['AuthLoginForm' => ['userModel' => 'AuthUsers']];
     $this->Auth->setAuthenticateObject(0, $AuthLoginFormAuthenticate);
     $this->Auth->request->data = ['AuthUsers' => ['username' => 'mark', 'password' => Security::hash('cake', null, true)]];
     $user = ['id' => 1, 'username' => 'mark'];
     $AuthLoginFormAuthenticate->expects($this->once())->method('authenticate')->with($this->Auth->request)->will($this->returnValue($user));
     $result = $this->Auth->identify();
     $this->assertEquals($user, $result);
     $this->assertSame($AuthLoginFormAuthenticate, $this->Auth->authenticationProvider());
 }
开发者ID:Rabp9,项目名称:test-psi2,代码行数:17,代码来源:AuthComponentTest.php

示例15: generateAuthKey

 /**
  * Generate authorization hash.
  *
  * @return string Hash
  */
 public static function generateAuthKey()
 {
     return Security::hash(String::uuid());
 }
开发者ID:maitrepylos,项目名称:nazeweb,代码行数:9,代码来源:Security.php


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