2017-01-24 181 views
-2

我想在laravel中使用sha1哈希某些字符串。但不管字符串是什麼,它們都返回相同的散列。請,我需要知道爲什麼是這樣,或者我做錯了什麼。見下面我的代碼:在Laravel中使用SHA 1哈希

$lice = $serial->sname.$serial->company.$serial->effDate.$serial->ltype; 
     //$serial->sname is MTS; 
     //$serial->company is Godowns Technology; 
     //$serial->effDate is 2017-01-24; 
     //$serial->ltype is Trial 

     $lice2= sha1($lice); 
     $lice3 = chunk_split($lice2,5,'-'); 
     $lice4 =strtoupper($lice3); 
    based on the information above, the $lice4 is always return: 
DA39A-3EE5E-6B4B0-D3255-BFEF9-56018-90AFD-80709 

請,我需要在這

+0

挑戰的第一個假設是'$ lice'設置正確。如果哈希結果總是相同,那麼壓倒性的最可能的情況是哈希值總是相同的。 – patricus

+2

這是一個空字符串的sha1-hash。 – Dilaz

+0

@Dilaz:這是否意味着變量沒有被提取?這就是爲什麼它是哈希空字符串 – Dave

回答

0

所有assitance,我所做的就是確保我的varibales來自形式獲取和他們正確定位。因此,一旦完成,我可以連接並獲得正確的散列。

$lice = $request->sname.$request->company.$request->effDate; 
     //$lice = $serial->sname; 
     $lice2= sha1($lice); 
     $lice3 = chunk_split($lice2,5,'-'); 
     $lice4 =strtoupper($lice3); 

     Serial::create([ 
     'sname' => $request->sname, 
     'company' => $request->company, 
     'effDate' => $request->effDate, 
     'ltype' => $request->ltype 
     ]);