Dan Hoover
Dan Hoover

Reputation: 235

Convert SHA256 Password Hashing Class to bcrypt in PHP

I have this hash class that I need to convert from SHA256 to bcrypt because I'm using it to store passwords. I can't seem to translate the documentation to my situation.

<?php
class Hash{
    public static function make($string, $salt = ''){
        return hash('sha256', $string . $salt);
    }

    public static function salt($length){
        return mcrypt_create_iv($length);
    }

    public static function unique(){
        return self::make(uniqid());
    }
}

Upvotes: 1

Views: 838

Answers (1)

Dan Hoover
Dan Hoover

Reputation: 235

The best way seemed to be to just change the logic in the forms from

password_hash(Input::get('password'),PASSWORD_DEFAULT),

to

password_hash(Input::get('password'), PASSWORD_BCRYPT, array('cost' => 12)),

My existing password_verify worked from my user class.

Upvotes: 3

Related Questions