本文整理汇总了PHP中Cake\Utility\Security类的典型用法代码示例。如果您正苦于以下问题:PHP Security类的具体用法?PHP Security怎么用?PHP Security使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Security类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: processAuthenticate
/**
* Authenticate users based on their JWT. This is inspired by
* the method _findUser in admads JWT plugin
*
* @see https://github.com/ADmad/cakephp-jwt-auth/blob/master/src/Auth/JwtAuthenticate.php
* @param string $token The token identifier.
* @param mixed $extra Unused
* @return array
*/
public function processAuthenticate($token, $extra = null)
{
try {
$token = JWT::decode($token, Security::salt(), Configure::read('Websockets.allowedAlgs'));
} catch (Exception $e) {
if (Configure::read('debug')) {
throw $e;
}
return ["FAILURE"];
}
if ($token->id == 'server') {
return ["SUCCESS", ["authid" => $token->id]];
}
$fields = Configure::read('Websockets.fields');
$table = TableRegistry::get(Configure::read('Websockets.userModel'));
$conditions = [$table->aliasField($fields['id']) => $token->id];
if (!empty(Configure::read('Websockets.scope'))) {
$conditions = array_merge($conditions, Configure::read('Websockets.scope'));
}
$result = $table->find('all')->where($conditions)->first();
if (empty($result)) {
return ["FAILURE"];
}
return ["SUCCESS", ["authid" => $result->id]];
}
开发者ID:gintonicweb,项目名称:websockets,代码行数:34,代码来源:JwtAuthenticationProvider.php
示例2: initialize
/**
* Initialize config data and properties.
*
* @param array $config The config data.
* @return void
*/
public function initialize(array $config)
{
if (!$this->_config['cypherKey']) {
$this->config('cypherKey', Security::salt());
}
$this->Cookie->configKey($this->config('cookieName'), ['key' => $this->config('cypherKey'), 'expires' => $this->config('period')]);
}
开发者ID:narendravaghela,项目名称:cakephp-remember-me,代码行数:13,代码来源:RememberMeComponent.php
示例3: urlBuilder
/**
* Get URL builder instance.
*
* @return \League\Urls\UrlBuilder URL builder instance.
*/
public function urlBuilder()
{
if (!isset($this->_urlBuilder)) {
$this->_urlBuilder = UrlBuilderFactory::create(Configure::read('Glide.serverConfig.base_url'), Configure::read('Glide.secureUrls') ? Security::salt() : null);
}
return $this->_urlBuilder;
}
开发者ID:josegonzalez,项目名称:cakephp-glide,代码行数:12,代码来源:GlideHelper.php
示例4: 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
示例5: tearDownAfterClass
/**
* Purge ConnectionManager configs.
*
* @return void
*/
public static function tearDownAfterClass()
{
foreach (self::$datasources as $ds => $configs) {
\Cake\Datasource\ConnectionManager::drop($ds);
}
\Cake\Utility\Security::salt('');
}
开发者ID:loadsys,项目名称:cakephp-basic-seed,代码行数:12,代码来源:BasicSeedShellTest.php
示例6: marshal
/**
* Marshalls request data into PHP strings.
*
* @param mixed $value The value to convert.
* @return mixed Converted value.
*/
public function marshal($value)
{
if ($value === null) {
return $value;
}
return base64_encode(Security::encrypt($value, Configure::read('Security.key')));
}
开发者ID:Xety,项目名称:Xeta,代码行数:13,代码来源:EncryptedSecurityType.php
示例7:
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
示例8: beforeDispatch
/**
* Callback for Routing.beforeDispatch event.
*
* @param \Cake\Event\Event $event The event instance.
*
* @return \Cake\Network\Response Response instance.
*/
public function beforeDispatch(Event $event)
{
$request = $event->data['request'];
$response = $event->data['response'];
$path = urldecode($request->url);
if (Configure::read('Glide.secureUrls')) {
SignatureFactory::create(Security::salt())->validateRequest('/' . $path, $request->query);
}
$server = ServerFactory::create(Configure::read('Glide.serverConfig'));
$cache = Configure::read('Glide.cache');
if ($cache) {
$timestamp = $server->getSource()->getTimestamp($server->getSourcePath($path));
$response->modified($timestamp);
if (!$response->checkNotModified($request)) {
$response = $server->getImageResponse($path, $request->query);
}
$response->cache($timestamp, $cache);
} else {
$response = $server->getImageResponse($path, $request->query);
}
$headers = Hash::filter((array) Configure::read('Glide.headers'));
foreach ($headers as $key => $value) {
$response->header($key, $value);
}
return $response;
}
开发者ID:josegonzalez,项目名称:cakephp-glide,代码行数:33,代码来源:GlideFilter.php
示例9: 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
示例10: setUp
/**
* setUp
*
* @return void
*/
public function setUp()
{
parent::setUp();
Security::salt('12345678901234567890123456789012345678901');
$this->controller = new Controller(new Request(), new Response());
$this->controller->loadComponent('Cookie');
$this->controller->loadComponent('Auth');
}
开发者ID:edukondaluetg,项目名称:Xeta,代码行数:13,代码来源:LanguageTest.php
示例11: 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
示例12: testMarshal
/**
* Test marshalling
*
* @return void
*/
public function testMarshal()
{
$this->assertNull($this->type->marshal(null));
$encrypted = $this->type->marshal('string');
$this->assertSame(128, strlen($encrypted));
$decrypted = Security::decrypt(base64_decode($encrypted), Configure::read('Security.key'));
$this->assertSame('string', $decrypted);
}
开发者ID:Xety,项目名称:Xeta,代码行数:13,代码来源:EncryptedSecurityTypeTest.php
示例13: token
public function token()
{
$user = $this->Auth->identify();
if (!$user) {
throw new UnauthorizedException('Invalid username or password');
}
$this->set(['success' => true, 'data' => ['token' => $token = \JWT::encode(['id' => $user['id'], 'exp' => time() + 604800], Security::salt())], '_serialize' => ['success', 'data']]);
}
开发者ID:jeffblack360,项目名称:cake3api,代码行数:8,代码来源:UsersController.php
示例14: boundary
/**
* Get the boundary marker
*
* @return string
*/
public function boundary()
{
if ($this->_boundary) {
return $this->_boundary;
}
$this->_boundary = md5(Security::randomBytes(16));
return $this->_boundary;
}
开发者ID:tgr0ss,项目名称:cakephp,代码行数:13,代码来源:FormData.php
示例15: 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
示例16: login
public function login($provider = null)
{
if ($provider) {
$config = ['path' => Router::url(['action' => 'login']) . '/', 'callback_url' => Router::url(['action' => 'callback']), 'security_salt' => Security::salt(), 'Strategy' => Configure::read('OpauthStrategy')];
$opauth = new \Opauth($config, true);
} else {
throw new NotFoundException();
}
}
开发者ID:ukatama,项目名称:cakephp3_opauthlogin,代码行数:9,代码来源:OpauthLoginController.php
示例17: token
public function token()
{
$user = $this->Auth->identify();
if (!$user) {
throw new UnauthorizedException('Invalid username or password');
}
$this->set('data', ['user' => $user, 'token' => $token = \JWT::encode(['id' => $user['id'], 'user' => $user, 'exp' => time() + 604800], Security::salt())]);
$this->ApiBuilder->execute();
}
开发者ID:hareshpatel1990,项目名称:cakephp-api,代码行数:9,代码来源:UsersController.php
示例18: decryptToken
/**
* Tries to decode, decrypt and unserialize the given token and return the data as an
* array
*
* @param string $token The string token
* @return array|false
*/
public function decryptToken($token)
{
$tokenData = false;
$encrypted = base64_decode($token);
if ($encrypted) {
$serialized = Security::decrypt($encrypted, Configure::read('Security.cryptKey'));
$tokenData = unserialize($serialized);
}
return $tokenData;
}
开发者ID:codekanzlei,项目名称:cake-cktools,代码行数:17,代码来源:UserToken.php
示例19: google
public function google()
{
$data = $this->request->input('json_decode');
$user = $this->Users->find('all')->where(['Users.provider' => 'facebook', 'Users.provider_uid' => $data->clientId])->first();
if (!$user) {
throw new UnauthorizedException('Invalid username or password');
}
$this->Auth->setUser($user);
$this->set(['success' => true, 'data' => ['token' => JWT::encode(['sub' => $user['id'], 'exp' => time() + 1800], Security::salt()), 'user_id' => $user['id']], '_serialize' => ['success', 'data']]);
}
开发者ID:shashin62,项目名称:cwed-api,代码行数:10,代码来源:UsersController.php
示例20: createToken
public function createToken()
{
$customer = $this->Customers->find('all', ['fields' => ['id', 'email', 'name', 'password'], 'conditions' => ['email' => $this->request->data('email'), 'gym_id' => $this->request->query('gym_id'), 'deleted' => false, 'is_active' => true]])->first();
if (!$customer || !(new DefaultPasswordHasher())->check($this->request->data('password'), $customer->password)) {
throw new UnauthorizedException('Invalid username or password');
}
$customer->sub = $customer->id;
unset($customer->password);
$this->set(['message' => ['user' => ['name' => $customer->name], 'token' => JWT::encode($customer->toArray(), Security::salt())]]);
$this->set('_serialize', ['message']);
}
开发者ID:ast-secret,项目名称:academia-webservice,代码行数:11,代码来源:CustomersController.php
注:本文中的Cake\Utility\Security类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论