1

For one of our site features, we create customer records programmatically using the customer's email and other information (address, first & last names, etc.) - the customer then just resets their password when they need to log in.

From what I can tell, Magento is generating a random encrypted password to use as a placeholder for the customer's password when the record is created. Is there a built in way to tell if a customer has created a password (or has never logged in)?

3 Answers 3

0

Is there a built in way to tell if a customer has created a password ?

No. There is no built in way to find this. The best approach would to log such an information in my opinion is:

  1. Create an attribute for customer, let's say is_customer_reset_password.
  2. Update this attribute value to 1 in customer reset password post action.

Is there a built in way to tell if a customer has never logged in ?

Again answer is no. But Magento provides an easy work around for this. For this, you can use below helper method:

/**
 * Use to check whether a customer logged in website ever !
 *
 * @param  Mage_Customer_Model_Customer $customer
 * @return boolean
 */
public function hasCustomerEverLoggedIn(Mage_Customer_Model_Customer $customer)
{
    $customerLog = Mage::getModel('log/customer')
            ->loadByCustomer($customer->getId());
    $date = $customerLog->getLoginAtTimestamp();
    if ($date) {
        return true;
    }
    return false;
}

Now pass your customer model to this helper method and you can easily find it out.

You can also find last login date of customer like this.

/**
 * Use to check whether a customer logged in website ever !
 *
 * @param  Mage_Customer_Model_Customer $customer
 * @return mixed
 */
public function getLastLoginDate(Mage_Customer_Model_Customer $customer)
{
    $customerLog = Mage::getModel('log/customer')
            ->loadByCustomer($customer->getId());
    $date = $customerLog->getLoginAtTimestamp();
    if ($date) {
        return Mage::helper('core')->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true);
    }
    return Mage::helper('customer')->__('Never');
}

In both these examples, we are using Mage_Log module which actually logs customer activities. So having a look into this core module might help you.


[This answer is a part of #mageStackDay5. It is an event conducted by Magento Community members as part of increasing the question-answer ratio. For more information http://www.magestackday.com/]

1

The password hash you see might be a hash of nothing, I wouldn't rely on it.

As for telling if a customer has logged in, you should be able to check the time stamp on the customer record for the last time they logged in. If it's null, they haven't logged in yet.

If you want anything more advanced than that you will need to add a custom module with an observer attached to the customer login event which sets a new customer attribute for "has logged in" to true if it is false.

1

The easiest way to find out if a customer logged in before is to check their last logged in information in the admin panel:

Customers > Manage Customers > Select Customer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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