Skip to content

Commit

Permalink
user random string
Browse files Browse the repository at this point in the history
  • Loading branch information
nadar committed Apr 23, 2024
1 parent cff5830 commit 3224e41
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,14 +589,16 @@ public function getId()
*/
public function getAuthKey()
{
// find user agent, if empty disable auto login
$userAgent = Yii::$app->request->userAgent;

// no user agent, dissable auto login
if (empty($userAgent)) {
return false;
}

$checksum = UserDevice::generateUserAgentChecksum($userAgent);
if (empty($checksum)) {
return false;
}

$model = UserDevice::find()->where(['user_id' => $this->id, 'user_agent_checksum' => $checksum])->one();

Expand All @@ -610,7 +612,7 @@ public function getAuthKey()
$model->user_id = $this->id;
$model->user_agent = $userAgent;
$model->user_agent_checksum = $checksum;
$model->auth_key = Yii::$app->security->generatePasswordHash(Yii::$app->security->generateRandomKey() . $checksum);
$model->auth_key = Yii::$app->security->generatePasswordHash(Yii::$app->security->generateRandomString() . $checksum);

if ($model->save()) {
return $model->auth_key;
Expand Down

0 comments on commit 3224e41

Please sign in to comment.