Forum Moderators: coopster

Message Too Old, No Replies

How to use SHA-256

         

DeezerD

7:01 pm on Aug 25, 2007 (gmt 0)

10+ Year Member



Hi there

I would like to know how to use SHA-256 to hash my passwords
It mhash the only function that can do it?
Code:

mhash(MHASH_SHA256,$string);

When I use mhash(), I get a string with weird caracters instead of something like "5b5cdff61cdb68ed059e39b3f9c82588"

Is it normal?
thanks for your help

TheAlbinoEthiopian

10:04 pm on Aug 25, 2007 (gmt 0)

10+ Year Member



I believe PHP5 has a sha256 function, but I haven't gotten anything to work on PHP4.

Little_G

10:50 pm on Aug 25, 2007 (gmt 0)

10+ Year Member



Hi,

Try,

bin2hex(mhash(MHASH_SHA256,$string));

Andrew

ps. As of PHP 5.3.0 mhash is obsoleted by Hash [php.net].

[edited by: Little_G at 10:56 pm (utc) on Aug. 25, 2007]

DeezerD

12:58 pm on Aug 26, 2007 (gmt 0)

10+ Year Member



thanks little_g
Would you then recommand to always use Hash() instead of mhash()?

Little_G

1:17 pm on Aug 26, 2007 (gmt 0)

10+ Year Member



Hi,

If you are using a version of PHP that supports it then you may as well, because mhash has been removed from PHP 5.3.0, so if you use Hash your scripts will be forward compatible with future updates to PHP.

Andrew

DeezerD

2:29 pm on Aug 26, 2007 (gmt 0)

10+ Year Member



thanks a lot for your very clear answer

Little_G

2:54 pm on Aug 26, 2007 (gmt 0)

10+ Year Member



Anytime!

Andrew