2017-01-24 83 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 
     ]);