如何在Laravel中使用SHA256



我目前正在做一个关于居住区二维码的Laravel项目。每次房主填写客人的详细信息时,系统都会生成一个唯一的6位数代码。现在,我只想散列SHA256中的唯一代码,但它不起作用。我能得到一些帮助吗?

这是我的GuestController:

<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
use AppModelsGuest;
use AppIlluminateSupportFacadesHash;
use SimpleSoftwareIOQrCodeFacadesQrCode;
class GuestController extends Controller
{
public function create()
{
return view('pages.guest.create');
}
public function store(Request $request)
{
$guest = new Guest;
$guest->code = random_int(100000, 999999);
$guest->hash = Hash::make(hash('sha256', $guest['code']));
$guest->guestname = $request->input('guestname');
$guest->guestphone = $request->input('guestphone');
$guest->guestic = $request->input('guestic');
$guest->guestcar = $request->input('guestcar');
$guest->datevisit = $request->input('datevisit');
$guest->timevisit = $request->input('timevisit');
$guest->save();

return redirect('show-pass')->with('status', 'Guest Added Successfully');
}
public function delete($id)
{
$guest = Guest::find($id);
$guest->delete();
return redirect('show-pass')->with('status', 'Guest Deleted Successfully');
}
public function generate($id)
{
$guest = Guest::findOrFail($id);
$qrcode = QrCode::size(150)->generate($guest->code);
return view('pages.guest.generate', compact('qrcode'));
}
public function search(Request $request)
{
//Get the search value from the request
$search = $request->input('search');
//Search in the code from the list
$guest = Guest::query()
->where('code', 'LIKE', "%{$search}%")
->get();

//Return the search view with the results compacted
return view('pages.guest.search', compact('guest'));
} 
}

您正在创建一个sha256哈希,然后通过Laravel的Hash门面使用bcrypt对该哈希进行哈希。Laravel的Hash立面仅支持bcryptArgon2。这就解释了为什么你会得到不同的结果。

只需使用普通的PHPhash()函数并删除LaravelHash

$guest->hash = hash('sha256', $guest['code']);

相关内容

  • 没有找到相关文章

最新更新