Commit 2bab6259 by Klimov Paul

'Security' helper usage switched to 'security' application component.

parent 54ac875e
...@@ -3,7 +3,7 @@ namespace common\models; ...@@ -3,7 +3,7 @@ namespace common\models;
use yii\base\NotSupportedException; use yii\base\NotSupportedException;
use yii\db\ActiveRecord; use yii\db\ActiveRecord;
use yii\helpers\Security; use Yii;
use yii\web\IdentityInterface; use yii\web\IdentityInterface;
/** /**
...@@ -147,7 +147,7 @@ class User extends ActiveRecord implements IdentityInterface ...@@ -147,7 +147,7 @@ class User extends ActiveRecord implements IdentityInterface
*/ */
public function validatePassword($password) public function validatePassword($password)
{ {
return Security::validatePassword($password, $this->password_hash); return Yii::$app->getSecurity()->validatePassword($password, $this->password_hash);
} }
/** /**
...@@ -157,7 +157,7 @@ class User extends ActiveRecord implements IdentityInterface ...@@ -157,7 +157,7 @@ class User extends ActiveRecord implements IdentityInterface
*/ */
public function setPassword($password) public function setPassword($password)
{ {
$this->password_hash = Security::generatePasswordHash($password); $this->password_hash = Yii::$app->getSecurity()->generatePasswordHash($password);
} }
/** /**
...@@ -165,7 +165,7 @@ class User extends ActiveRecord implements IdentityInterface ...@@ -165,7 +165,7 @@ class User extends ActiveRecord implements IdentityInterface
*/ */
public function generateAuthKey() public function generateAuthKey()
{ {
$this->auth_key = Security::generateRandomKey(); $this->auth_key = Yii::$app->getSecurity()->generateRandomKey();
} }
/** /**
...@@ -173,7 +173,7 @@ class User extends ActiveRecord implements IdentityInterface ...@@ -173,7 +173,7 @@ class User extends ActiveRecord implements IdentityInterface
*/ */
public function generatePasswordResetToken() public function generatePasswordResetToken()
{ {
$this->password_reset_token = Security::generateRandomKey() . '_' . time(); $this->password_reset_token = Yii::$app->getSecurity()->generateRandomKey() . '_' . time();
} }
/** /**
......
<?php <?php
use yii\helpers\Security;
return [ return [
'username' => 'userName', 'username' => 'userName',
'auth_key' => function ($fixture, $faker, $index) { 'auth_key' => function ($fixture, $faker, $index) {
$fixture['auth_key'] = Security::generateRandomKey(); $fixture['auth_key'] = Yii::$app->getSecurity()->generateRandomKey();
return $fixture; return $fixture;
}, },
'password_hash' => function ($fixture, $faker, $index) { 'password_hash' => function ($fixture, $faker, $index) {
$fixture['password_hash'] = Security::generatePasswordHash('password_' . $index); $fixture['password_hash'] = Yii::$app->getSecurity()->generatePasswordHash('password_' . $index);
return $fixture; return $fixture;
}, },
'password_reset_token' => function ($fixture, $faker, $index) { 'password_reset_token' => function ($fixture, $faker, $index) {
$fixture['password_reset_token'] = Security::generateRandomKey() . '_' . time(); $fixture['password_reset_token'] = Yii::$app->getSecurity()->generateRandomKey() . '_' . time();
return $fixture; return $fixture;
}, },
......
...@@ -9,7 +9,6 @@ namespace yii\web; ...@@ -9,7 +9,6 @@ namespace yii\web;
use Yii; use Yii;
use yii\base\InvalidConfigException; use yii\base\InvalidConfigException;
use yii\helpers\Security;
use yii\helpers\StringHelper; use yii\helpers\StringHelper;
/** /**
...@@ -1188,7 +1187,7 @@ class Request extends \yii\base\Request ...@@ -1188,7 +1187,7 @@ class Request extends \yii\base\Request
if ($this->enableCookieValidation) { if ($this->enableCookieValidation) {
$key = $this->getCookieValidationKey(); $key = $this->getCookieValidationKey();
foreach ($_COOKIE as $name => $value) { foreach ($_COOKIE as $name => $value) {
if (is_string($value) && ($value = Security::validateData($value, $key)) !== false) { if (is_string($value) && ($value = Yii::$app->getSecurity()->validateData($value, $key)) !== false) {
$cookies[$name] = new Cookie([ $cookies[$name] = new Cookie([
'name' => $name, 'name' => $name,
'value' => @unserialize($value), 'value' => @unserialize($value),
...@@ -1218,7 +1217,7 @@ class Request extends \yii\base\Request ...@@ -1218,7 +1217,7 @@ class Request extends \yii\base\Request
public function getCookieValidationKey() public function getCookieValidationKey()
{ {
if ($this->_cookieValidationKey === null) { if ($this->_cookieValidationKey === null) {
$this->_cookieValidationKey = Security::getSecretKey(__CLASS__ . '/' . Yii::$app->id); $this->_cookieValidationKey = Yii::$app->getSecurity()->getSecretKey(__CLASS__ . '/' . Yii::$app->id);
} }
return $this->_cookieValidationKey; return $this->_cookieValidationKey;
...@@ -1323,7 +1322,7 @@ class Request extends \yii\base\Request ...@@ -1323,7 +1322,7 @@ class Request extends \yii\base\Request
{ {
$options = $this->csrfCookie; $options = $this->csrfCookie;
$options['name'] = $this->csrfParam; $options['name'] = $this->csrfParam;
$options['value'] = Security::generateRandomKey(); $options['value'] = Yii::$app->getSecurity()->generateRandomKey();
return new Cookie($options); return new Cookie($options);
} }
......
...@@ -12,7 +12,6 @@ use yii\base\InvalidConfigException; ...@@ -12,7 +12,6 @@ use yii\base\InvalidConfigException;
use yii\base\InvalidParamException; use yii\base\InvalidParamException;
use yii\helpers\Url; use yii\helpers\Url;
use yii\helpers\FileHelper; use yii\helpers\FileHelper;
use yii\helpers\Security;
use yii\helpers\StringHelper; use yii\helpers\StringHelper;
/** /**
...@@ -371,7 +370,7 @@ class Response extends \yii\base\Response ...@@ -371,7 +370,7 @@ class Response extends \yii\base\Response
foreach ($this->getCookies() as $cookie) { foreach ($this->getCookies() as $cookie) {
$value = $cookie->value; $value = $cookie->value;
if ($cookie->expire != 1 && isset($validationKey)) { if ($cookie->expire != 1 && isset($validationKey)) {
$value = Security::hashData(serialize($value), $validationKey); $value = Yii::$app->getSecurity()->hashData(serialize($value), $validationKey);
} }
setcookie($cookie->name, $value, $cookie->expire, $cookie->path, $cookie->domain, $cookie->secure, $cookie->httpOnly); setcookie($cookie->name, $value, $cookie->expire, $cookie->path, $cookie->domain, $cookie->secure, $cookie->httpOnly);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment