2017-06-29 2 views
-5

Ich benutze PHP 7.1.6. Ich versuche, password_hash zu verwenden, aber es scheint nicht zu funktionieren. Hier ist mein Code:Password_hash nicht Hashing

$post = $this->input->post(); 
$maxid = $this->db->query('SELECT MAX(App_Users.ID) AS MAXID FROM App_Users')->row()->MAXID; 
$maxid = $maxid + 1; 
$hash = password_hash($post['Password'], PASSWORD_DEFAULT); 
$this->db->query("INSERT INTO APP_USERS (ID, NAME, PASSWORD) 
VALUES(".$maxid.", '".$post['Name']."', '". $hash ."')"); 

Das Passwort wird ohne Hashing gespeichert. $ post ['Passwort'] = '1234' und es wird in der DB als '1234' gespeichert.

Mache ich etwas falsch?

+1

'$ post 'kommt von wo? –

+0

Bitte, var_dump $ post – MorganFreeFarm

+1

'$ hash' ist eine Zeichenkette, keine Ganzzahl - Edit: einmal' password_hash() 'tritt ein. –

Antwort

-1
//this is normal way to generate has password// 
$hash = password_hash("input value", PASSWORD_DEFAULT); 
$this->db->query("INSERT INTO APP_USERS (ID, NAME, PASSWORD) 
VALUES(".$maxid.", '".$post['Name']."', '". $hash ."')"); 

//In this way we can provide cost and salt to generate hash value// 

$options = [ 
'cost' => 11, 
'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM), 
]; 
$hash = password_hash("input value", PASSWORD_BCRYPT, $options); 

Eingangswert das, was Sie $ post [ 'der Wert, den Sie Hashing wollen'] haben SENING durch.

Hoffe, es wird dir helfen

+0

Es wird empfohlen, kein Salz anzugeben, sondern 'password_hash' das Salz zu erzeugen. Auch in PHP 7.x wurde die Salz Option entfernt. Siehe [password_hash] (http://php.net/manual/en/function.password-hash.php), "Wenn nicht angegeben, wird von password_hash() ein zufälliges Salz für jedes gehashte Passwort generiert. Dies ist der beabsichtigte Modus Betriebs." – zaph