Answer the question
In order to leave comments, you need to log in
How to customize validatePassword() function from \vendor\yiisoft\yii2\base\Security.php?
What needs to be done is to be able to use ucoz passwords.
You just need to make a couple of changes and everything will work properly, but how to do it. I understand that in vendor this is fraught with the loss of changes when updating.
Answer the question
In order to leave comments, you need to log in
I didn’t find how to do it through DI ... offhand I did it like this, oddly enough, but it worked. Can you correct me if it's wrong?
Added to common/config/main.php
'components' => [
// ...
'security' => [
'class' => 'common\components\CommSecurity',
],
],
<?php
namespace common\components;
use yii\base\Security;
use Yii;
class CommSecurity extends Security
{
public function validatePassword($password, $hash)
{
if (!is_string($password) || $password === '') {
throw new InvalidParamException('Password must be a string and cannot be empty.');
}
if (function_exists('password_verify')) {
return password_verify($password, $hash);
}
$test = crypt($password, $hash);
$n = strlen($test);
if (($n !== 60) && ($n !== 30)) {
return false;
}
return $this->compareString($test, $hash);
}
}
Make a separate class. Do not touch Security. The one who will be engaged in the project after you will thank you.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question