TDoG-Skin/app/Models/Concerns/HasPassword.php
2024-08-17 19:13:54 +08:00

34 lines
852 B
PHP
Executable File

<?php
namespace App\Models\Concerns;
use App\Services\Cipher\BaseCipher;
use Blessing\Filter;
trait HasPassword
{
public function verifyPassword(string $raw)
{
/** @var BaseCipher */
$cipher = resolve('cipher');
/** @var Filter */
$filter = resolve(Filter::class);
$password = $this->password;
$user = $this;
$passed = $cipher->verify($raw, $password, config('secure.salt'));
$passed = $filter->apply('verify_password', $passed, [$raw, $user]);
return $passed;
}
public function changePassword(string $password): bool
{
$password = resolve('cipher')->hash($password, config('secure.salt'));
$password = resolve(Filter::class)->apply('user_password', $password);
$this->password = $password;
return $this->save();
}
}