larave账号加密和检查,注册和登录
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