Skip to main content

Posts

Showing posts with the label cakephp

Cakephp 4: How to convert string to hash password

CakePHP 4: How to convert string to hash password This tutorial works for both CakePHP  3 and CakePHP 4. Sometimes we want to add custom login or wants to add custom login  or we want client side password hashing using cakephp Hash functions , so for that we need to use DefaultPasswordHasher which provides inbuilt functionality to check two passwords , compare it or convert a string to Hash etc. To use password hashing please follow below steps:- Step 1 Call a class after the namespace. use Cake\Auth\DefaultPasswordHasher; Step 2 Now we can use functions of DefaultPasswordHasher().  Use below code to change a simple string password to a secure string and its non reversible . $password = "My Password String"; $hasher = new DefaultPasswordHasher(); $newPassword = $hasher->hash($password);  Now if you print $newPassword to test its working or not, then you will get it an unique hash everytime on refresh, because CakePHP use different mechanism to handle hash that is ...

Cakephp Cross-site request forgery validation failed. Required param “state” missing Facebook Login Solution

Solution : Cakephp Facebook Login Cross-site request forgery validation failed. Required param “state” missing. When we try to integrate Facebook Login(Social Login with Facebook) with CakePHP, sometimes we get an error like "Facebook SDK error: Cross-site request forgery validation failed. Required param “state” missing from persistent data" Question: Why I am getting this error? Answer: This is the session issue because Facebook handles access token and csrf with session and most frameworks like laravel, YII, Codeigniter, CakePHP handles session differently compare to CorePHP, So we need to change session handler according to the framework. For this tutorial, I am using CakePHP 4 version but it will be the same for CakePHP 3 also. So first we will create our custom session handler. so create a new file in src\Handler\MyFbPersistentDataHandler.php NOTE: If the Handler folder does not exists by default then create it and then create a file in it. <?php...