sha256 check -- default to MD5

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

sha256 check -- default to MD5

Post by alex.barylski »

I have this incredibly complex function:

Code: Select all

    
function calc_hash($value)
{
    if(function_exists('hash')){
        return hash('sha256', $value);
    }
 
    return md5($value);
}
Is this enough to ensure the right function is called? Is there a way to check if sha256 is installed as a extension or does it alwasy come with the hash() familiy?
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Re: sha256 check -- default to MD5

Post by aaronhall »

alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: sha256 check -- default to MD5

Post by alex.barylski »

Perfect. :)

Thank you :)
Post Reply