Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined function sha256()

I have this php code:

$password = sha256($_POST['password']);

but when I run this code it says:

Fatal error: Call to undefined function sha256() in .... on line ...ix it as 

What is wrong with this code and what must I do to fix this as I know that sha256 exists.

I have also tried:

$password = sha256(trim($_POST['password']));

But that doesn't work either.

like image 491
H Bellamy Avatar asked Dec 16 '11 11:12

H Bellamy


2 Answers

You can use

hash( 'sha256', $string );

See http://de.php.net/manual/de/function.hash.php

like image 61
DarkDevine Avatar answered Sep 17 '22 20:09

DarkDevine


The Suhosin extension adds the function sha256(), and even sha256_file(), to the PHP Core.

With the extension installed:

<?php
var_dump(function_exists('sha256'));
?>

bool(true)
like image 45
Goran Miskovic Avatar answered Sep 19 '22 20:09

Goran Miskovic