Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter 3 to 4 migration - hash encryption
#1

(This post was last modified: 05-08-2024, 01:43 AM by hqualit. Edit Reason: missed CI4 in the content )

I am in the middle of the migration to CI4 from CI3. In CI3 version we have used the below method on user registration and saved $salt and $password in the db.  $salt     = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), TRUE));

$salt    = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), TRUE));
$password = hash('sha512', $data['password'] . $salt);
When user login we have used the below method. 
$results = $query->getRowArray();
$salted_password = hash('sha512', $password . $results['salt']);
 if ($results['password'] == $salted_password) { return true; }
The same code used in CI4 too.
But the login is giving password mismatch with the existing users credentials. But it works totally fine with the new registered user. Do anyone has idea how I should change this code to work with the existing users' credentials?
Reply
#2

hash() is a PHP function.
https://www.php.net/manual/en/function.hash.php

So it should work both CI3 and CI4. So I don't know why you have this issue.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB