Skip to main content

Override Magento Module MD5 to SHA1



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.



\app\code\core\Mage\Core\Model\Encryption.php.

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. 

Comments

  1. Hey Lansantha,

    I 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

    ReplyDelete

Post a Comment

Popular posts from this blog

How To Disable Export Button In Crystal Report When you are taking crystal report printouts through a program, such as program written using vb6. you might have a problem how to disable Export button in print preview. All you have to change following property to false or Uncheck the Export option in Property Pages. You CR.WindowShowExportBtn = False Crystal Report Object in Visual Basic 6. (CR is refer to Crystal Report Object ) You can go to Property Pages by right click and choose Properties on Crystal Report Object After you done those things you crystal Report print preview will showing like follows. I was face to above problem. We implemented a software program which is written using vb6. Cashier can take daily sale print out. before printing it is showing a preview to the user. So when the time pass user click export button and saved that report as a excel file. Then he modified the values and took printout to the management. That gives Security problem to the program a...

Application Configuration FIle Visual Studio 2005

Through the application configaration file You can easily save values to later usage. you can create a application configuration file from project > Add New Item (Ctrl + Shift + A) example You want to add get string from config file Create a Config file using above step. after that insert following code to the config file. its a XML file. appsettings add key="DatabasePath" value="c:\\projects\data\spider.mdb" add key="SupportEmail" value="webmaster-1@dotnetspider.com" appsettings configuration in the coding add following Dim app As New System.Configuration.AppSettingsReader Dim s As String s = app.GetValue("DatabasePath", Type.GetType("System.String")) MessageBox.Show(s) its very easy when you are handling databases. you can store database connection string in that config for later reusabilty. Please post your comments