How to encrypt a password field using BCRYPT using DataTables Editor in PHP?
How to encrypt a password field using BCRYPT using DataTables Editor in PHP?

In one of my PHP based application, I am using DataTables Editor for CRUD functionality. Everything is OK until when I am trying to register a user. I want to use a custom hashing using PHP PASSWORD_BCRYPT rather than the DataTables default one.
But the problem is I can't figure out where I need to do that and how to do that!
Here is the function that I want to use in DataTables Editor for password hashing.
function encryption($password)
{
$data = $password;
$hash = "";
if (version_compare(PHP_VERSION, '7.0', '>=')) {
$hash = password_hash($data, PASSWORD_BCRYPT);
} else {
$options = [
'cost' => 10,
'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM),
];
$hash = password_hash($data, PASSWORD_BCRYPT, $options); //options is deprecated from PHP 7.0
}
return $hash;
}
Can anyone help me?
This question has an accepted answers - jump to answer
Answers
Use a custom setFormatter that will execute your encryption function and return the hash which will then be written to the database.
Allan
How can I write a custom setFormatter? Can you please provide any idea?
Here is something from my own coding. A password and a repeat password with validation plus get and set formatting.
The documentation shows a
getFormatter
code example and also notes that thesetFormatter
is basically the same.Allan