Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

I want to encrypt customer data like email,name,addresses. I have created new class to encrypt and decrypt data. For encryption , i'll have to use AccountController.php (i'll be overriding app/code/core/Mage/Customer module) Please let me know where should i use encryption function in createPostAction()

public function createPostAction()
{

    /** @var $session Mage_Customer_Model_Session */
    $session = $this->_getSession();
    if ($session->isLoggedIn()) {
        $this->_redirect('*/*/');
        return;
    }
    $session->setEscapeMessages(true); // prevent XSS injection in user input
    if (!$this->getRequest()->isPost()) {
        $errUrl = $this->_getUrl('*/*/create', array('_secure' => true));
        $this->_redirectError($errUrl);
        return;
    }

    $customer = $this->_getCustomer();

    try {
        $errors = $this->_getCustomerErrors($customer);

        if (empty($errors)) {
            $customer->save();
            $this->_dispatchRegisterSuccess($customer);
            $this->_successProcessRegistration($customer);
            return;
        } else {
            $this->_addSessionError($errors);
        }
    } catch (Mage_Core_Exception $e) {
        $session->setCustomerFormData($this->getRequest()->getPost());
        if ($e->getCode() === Mage_Customer_Model_Customer::EXCEPTION_EMAIL_EXISTS) {
            $url = $this->_getUrl('customer/account/forgotpassword');
            $message = $this->__('There is already an account with this email address. If you are sure that it is your email address, <a href="%s">click here</a> to get your password and access your account.', $url);
            $session->setEscapeMessages(false);
        } else {
            $message = $e->getMessage();
        }
        $session->addError($message);
    } catch (Exception $e) {
        $session->setCustomerFormData($this->getRequest()->getPost())
            ->addException($e, $this->__('Cannot save the customer.'));
    }
    $errUrl = $this->_getUrl('*/*/create', array('_secure' => true));
    $this->_redirectError($errUrl);
}

Thanks in advance

share|improve this question

closed as unclear what you're asking by Marius, Flyingmana, Fabian Blechschmidt, davidalger, philwinkle Feb 20 at 17:11

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

    
No you don't want this. You destroy the whole logic in mysql, because you can't filter or order. –  Fabian Blechschmidt Feb 20 at 9:41
1  
If your customer wants the data encrypted, encrypt the hard disk, use SSL/TLS everywhere and get a great admin –  Fabian Blechschmidt Feb 20 at 10:27
1  
this will give no real gain, as the decryption keys are stored together with the db connection –  Flyingmana Feb 20 at 11:39
    
@Flyingmana But i'm using new class for encryption not encryptionkey that written in local.xml file. –  Aniruddha A Deshpande Feb 20 at 11:44
1  
its still in the same server in the same access scope as your local.xml –  Flyingmana Feb 20 at 11:45

2 Answers 2

Encrypting data isn't the issue. The following code snippet will encrypt data using Magento's build in encryption library

Mage::getModel('core/encryption')->encrypt('foobiedoo'); // returns encrypted string

The issue is that the data you're trying to encrypt is used all over Magento and is expected to be readily available. Like, for example, when a user logs in Magento needs to be able to search for the email address in the database.

Now you can probably get this to work by encrypting the input data when a user logs in for example but doing this for all the times Magento is using customer data will be a lot of work. Think about the customer data in the checkout, the customer grid in the admin area and so on.

My advice, encrypt only the most sensitive data like Credit Card numbers and invest your time in securing any 3th party extensions from SQL injections and that sort of attacks. The change of a hacker getting in to your installation and getting his hands on your customer data will be highly unlikely. Also there are companies that offer services to scan your webshop for possible security treads. That might be something you want to look into.

share|improve this answer
    
+1 for "securing any 3th party extensions from SQL injections and that sort of attacks" –  Fabian Blechschmidt Feb 20 at 9:59

I think you should better write a observer, hook into customer_save_before and customer_save_after and maybe address, and other entities and then just run:

$encrypted = array_map((Mage::helper('core'), )$customer->getData());
$customer->setData($encrypted);

This is simplified! Of course you want only encrypt the data which needs to be encrypted. Especially the foreign keys, etc. shouldn't be broken.

And in the save_after you want to decrypt again everything.

share|improve this answer
    
Not sure why you got downvoted. The observers are a great approach. But you would still run into issues any time Magento needs the data I guess? –  Sander Mangel Feb 20 at 10:25
    
The idea is: Load encrypted data, decrypt them, so you can use them over the whole system. Problem with MySQL querying still exists, yes. You can't repair this idea. The approach is broken. –  Fabian Blechschmidt Feb 20 at 10:26
    
Overwrite all Resource classes of the customer model to decrypt whenever AddAttributeToFilter/Select is called on a customer collection would be required and much more. You probably wouldn't have this stable before Magento 2.0 launches ^^ –  Sander Mangel Feb 20 at 10:29
    
It is even worse, because encryption differs between upper and lowercase, mysql doesn't. and there is no way except CASE, CASe, CAsE, CaSE, cASE, CAse, ... to search for things. and ordering doesn't work too. –  Fabian Blechschmidt Feb 20 at 10:55
    
1) Encryption is single way task we can encrypt data , but decryption requires at checkout,edit profile also backend. 2)Is it fine to use decryption function when ever require for e.g. in function > public function forgotPasswordPostAction() to search email 3) Actually i tried to encrypt data by using new function >public function encryption($userDatas) used this function in > public function createPostAction() in line > $customerForm->extractData($this->getRequest()) and got output as > Array ( [firstname] => encryptedFname [lastname] => encryptedLname [email] => encryptedEmail ) –  Aniruddha A Deshpande Feb 20 at 11:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.