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

Magento Generate Google Sitemap using Cron

I had a problem with generating the Google sitemap using cron job. To do that you can simply change following database value. SELECT * FROM core_config_data WHERE path = 'crontab/jobs/sitemap_generate/schedule/cron_expr' Change the value as you set time in cron jobs. EX: Generate the Sitemap for every 5 minutes value = */5 * * * * That's it. Now you have to worry about cron is working or not. Just type following in your browser and hit enter. http://youresite.com/cron.php
Git script which shows little bit advanced status. Save with Preferred file name in /usr/local/bin/XX branch="" branches="git branch --list" ESC_SEQ="\x1b[" COL_RESET=$ESC_SEQ"39;49;00m" COL_RED=$ESC_SEQ"31;01m" while read -r branch; do clean_branch_name=${branch//\*\ /} description=`git config branch.$clean_branch_name.description` if [ "${branch::1}" == "*" ]; then printf "$COL_RED$branch$COL_RESET $description \n" else printf " $branch $description\n" fi done <<< "$branches" git status Use the following command to add a description to your local branches. git branch --edit-description