Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Quote:
I have Hash class as follows:

class Hash
	{
		public static function make($string, $salt='')
		{
			echo $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());
		}
	}



I am colling method salt() with command:
$salt=Hash::salt(32)

Unfortunatelly, function mcrypt_create_iv is not working on newer php.

How to redesign Hasch class?

Thank you


What I have tried:

Tried different options with different crypt methods, but not working with Hash class as it is designed
Posted
Updated 1-Nov-20 15:48pm
Comments
Richard MacCutchan 22-Nov-19 8:02am    
"function mcrypt_create_iv is not working on newer php"
What does the documentation say for that function?
Sinisa Janjetovic 22-Nov-19 8:10am    
It says that it is not supported any more
Richard MacCutchan 22-Nov-19 9:45am    
Well, that is the answer. It is always worth checking the documentation before posting your question.
Sinisa Janjetovic 22-Nov-19 11:58am    
Thank you very much, but I was looking for alternative.
Richard MacCutchan 22-Nov-19 12:49pm    
It's in the documentation.

1 solution

Change out the 2nd one using mcrypt with....

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


I have it working with php7.4.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900