larave账号加密和检查,注册和登录
xuexi 2025-11-20 16:14:30 发表在:PHP 查看数:125
use App\Models\User;
use Illuminate\Support\Facades\Hash;

// 创建用户并加密密码
$user = User::create([
    'name' => '张三',
    'email' => 'zhangsan@example.com',
    'password' => Hash::make('123456'), // 生成安全哈希
]);

// 登录时验证密码
$inputPassword = '123456'; // 用户输入的密码
if (Hash::check($inputPassword, $user->password)) {
    echo '密码正确!';
    //  return response()->json(['code' => '不正确的code'],401);
}
最近访问时间:2025-12-22 12:24:46
知识库:407条鸣谢:TAY  备案号:蜀ICP备2024090044号-1