Override Magento Module MD5 to SHA1
Here I am going to override the hash function in Encryption
class to sha1 instead of md5.
Original file is located in below path.
To override above function I will follow standards given by Magento.
First I will create the directory structure.
For this example I will use MyNameSpace as my Module name
\app\code\local\MyNameSpace\MyModule
\app\code\local\MyNameSpace\MyModule\Block
\app\code\local\MyNameSpace\MyModule\controllers
\app\code\local\MyNameSpace\MyModule\etc
\app\code\local\MyNameSpace\MyModule\Helper
\app\code\local\MyNameSpace\MyModule\Model
\app\code\local\MyNameSpace\MyModule\sql
Second I am going to create the Source files which are
needed for this task.
Create the MyNameSpace_All.xml in following path and save it
with below codes.
As you know this file will tells to Magento that we are
using MyModule
Module.
\app\etc\modules\MyNameSpace_All.xml
<?xml version="1.0"?>
<config>
<modules>
<MyNameSpace_MyModule>
<active>true</active>
<codePool>local</codePool>
</MyNameSpace_MyModule>
</modules>
</config>
Add the following codes in below file (you have to create as
normally do).
config.xml explain using xml comments J.
\app\code\local\MyNameSpace\MyModule\etc\config.xml
<?xml version="1.0"?>
<config>
<modules>
<MyNameSpace_MyModule>
<version>0.1.0</version>
<depends>
<Mage_Core />
</depends>
</MyNameSpace_MyModule>
</modules>
<global>
<models>
<core>
<rewrite>
<encryption>MyNameSpace_MyModule_Model_Encryption</encryption>
</rewrite>
</core>
</models>
<helpers>
<core>
<encryption_model>MyNameSpace_MyModule_Model_Encryption</encryption_model>
</core>
</helpers>
</global>
<frontend>
<routers>
<mynamespace_mymodule>
<use>standard</use>
<args>
<module>MyNameSpace_MyModule</module>
<frontName>mymodule</frontName>
</args>
</mynamespace_mymodule>
</routers>
</frontend>
</config>
Writeing the new Encryption Class which will have the new
hashing function
\app\code\local\MyNameSpace\MyModule\Model\Encryption.php
<?php
class MyNameSpace_MyModule_Model_Encryption extends Mage_Core_Model_Encryption
{
public function hash($data)
{
return sha1($data);
}
}
?>
Ok Done. You can try sha and md5 difference now. I checked
through when registering a new customer. New sha1 values located in
customer_entity_varchar table in your database.
Hey Lansantha,
ReplyDeleteI tried to rewrite the helper, but then I can't open the page for backend (/admin).
Which version of Magento are you using?
Greetz Sven