Answer the question
In order to leave comments, you need to log in
Yii2 HTTP Basic authentication how to do?
Hello. I can’t understand how Basic authentication is implemented in the rest of Yii2 - I found a way on the forum:
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['authenticator'] = [
'class' => HttpBasicAuth::className(),
'auth' => [$this, 'auth']
];
return $behaviors;
}
public function auth($username, $password)
{
$user = User::findOne(['username' => $username]);
if ($user->validatePassword($password)) {
return true;
}
else {
return false;
}
}
Answer the question
In order to leave comments, you need to log in
It is necessary not to crawl on the forum. And to the documentation .
Here's a finished example for you . Dmitry once gave you a video of Dmitry Eliseev via API
. You first study, look, then there will be no questions left. If you are too lazy to look for a long time, that is , Maxim has a shorter
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question