i have created a module and it’s override magento hash function properly.
But question is, i want to check some conditions.
if admin login,
else if soap api user login ,
else if customer,
else if migration customer
My Question is , how we track which type request coming to getHash function?
<?php
class Namespace_ShaModule_Model_Encryption extends Mage_Core_Model_Encryption
{
public function hashSHA($password){
return sha1($password);
}
public function hashMD5($password){
return md5($password);
}
public function noHash($password){
return $password;
}
public function validateHash($password, $hash) {
return $this->hash($password) === $hash;
}
public function getHash($password, $salt = false)
{
return $this->hash($password);
}
public function hash($data){
if(admin_login_handling_and_api_user_accounts){
return $this->hashMD5($password);
} else if(Magento_customer_handling){
return $this->hashSHA($password);
}else if(soap_Api_customer_handling){
return $this->noHash($password);
}
}
}
?>
From my point of view, this action maynot be in Encryption class’s scope. The Encryption class should take the password as parameter and return as hashed password. So in order to implement your requirement, you may add an additional parameter to function getHash, like
And then a few investigation may be taken to insert to the core code or write an additional module to do this. For example, you may add the $type variable to the customer login and register process to make a change at the hash function. It may be quite exhausting to do digging into core file just like this. Moreover, it’s better for you to have a Encryption Factory to manage this or other design pattern issues.
Another way is so tricky that I just write here as reference, but not recommend this. It is to use the function debug_backtrace() to check who call the getHash() function and determine the type inside the getHash() function. I don’t know the system requirements and resource usage when using such kind of function. It may be helpful to solve this problem but bare lots of deficits.
Hope this is helpful to you 🙂