Monday, November 19, 2012

Create a custom module for change encryption mechanism inside magento

This is my first experience with mageto custom module creation.

first you should create below folder structure in you magento installation.My module name is ShaModule and my custom module creating package is Sanji.If i create another custom module  then i can put that module also inside the Sanji package.

mageto/app/code/local/Sanji/ShaModule
mageto/app/code/local/Sanji/ShaModule/Block
mageto/app/code/local/Sanji/ShaModule/controllers
mageto/app/code/local/Sanji/ShaModule/etc
mageto/app/code/local/Sanji/ShaModule/Helper
mageto/app/code/local/Sanji/ShaModule/Model
mageto/app/code/local/Sanji/ShaModule/sql

Then you create module files.

mageto/app/code/local/Sanji/ShaModule/ShaModule.php
in this module its an empty file.
####################################################################

mageto/app/code/local/Sanji/ShaModule/etc/config.xml

this is the content of config.xml file.



<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : config.xml
    Created on : July 26, 2012, 1:12 PM
    Author     : sanjeewani
    Description:
        Purpose of the document follows.
-->

<config>
    <modules>
        <Sanji_ShaModule>
            <version>0.1.0</version>
            <depends>
             <Mage_Core />
            </depends>
        </Sanji_ShaModule>
    </modules>

    <global>
        <models>
            <core>
                <rewrite>
                 <encryption>Sanji_ShaModule_Model_Encryption</encryption>
                </rewrite>
            </core>
        </models>
        <helpers>
            <core>
             <encryption_model>Sanji_ShaModule_Model_Encryption</encryption_model>
            </core>
        </helpers>
    </global>

    <frontend>
        <routers>
            <sanji_shamodule>
             <use>standard</use>
                <args>
                    <module>Sanji_ShaModule</module>
                    <frontName>shamodule</frontName>
                </args>
            </sanji_shamodule>
        </routers>
    </frontend>
</config>


########################################################################
mageto/app/code/local/Sanji/ShaModule/Model/Encryption.php
you should override the parent encryption function inside your module. so extend  parent class to your model class.


<?php
class Sanji_ShaModule_Model_Encryption extends Mage_Core_Model_Encryption
{

   public function getHash($password, $salt = false)
    {
        return $this->hash($password);
    }
   public function hash($data){
       //die('came');

        return sha1($data); //magento through create customer and other
    }

    public function validateHash($password, $hash) {
        return $this->hash($password) === $hash;

        }
}
?>


####################################################################
put this file to below path Sanji_ShaModule.xml.this is the your module installation file to magento.
magento/app/etc/modules/

content of Sanji_ShaModule.xml file is below.


<?xml version="1.0" encoding="UTF-8"?>

<!--
    Document   : Sanji_ShaModule.xml
    Created on : July 26, 2012, 1:17 PM
    Author     : sanjeewani
    Description:
        Purpose of the document follows.
-->


<config>

    <modules>

        <Sanji_ShaModule>

            <active>true</active>

            <codePool>local</codePool>

        </Sanji_ShaModule>

    </modules>

</config>




****
Make sure clear session data and cache data  from magento.
session data path -magento/var/session/
cache data path   -magento/var/cache/
****


After that go to admin login page  and  go with your admin username and password. I think  can't log with previous account password. then you go to database and change password (sha1('password')) with sha1 value. then you can log and change every thing with sha1 encryption.

No comments:

Post a Comment