I dont want my customer to enter password while creating account in magento.When customer creates account password should be auto generated and mail should be sent to that customer .Can anybody help me out plz…
Magento – How to generate random password for new customer while creating account in magento
customer
Related Solutions
Take a look at Magento Migrate customers with no password.
$customer = Mage::getModel('customer/customer');
$password = '123456';
$email = 'testuser@test.com';
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail($email);
if($customer->getId()) { // if customer does not already exists, by email
$newPassword = $customer->generatePassword(); // generate a new password
$customer->changePassword($newPassword); // set it
$customer->save();
}
Assuming that you want to use the default magento password template then take a look at app/code/core/Mage/Adminhtml/controllers/CustomerController.php
// Send welcome email
if ($customer->getWebsiteId() && (isset($data['account']['sendemail']) || $sendPassToEmail)) {
$storeId = $customer->getSendemailStoreId();
if ($isNewCustomer) {
$customer->sendNewAccountEmail('registered', '', $storeId);
} elseif ((!$customer->getConfirmation())) {
// Confirm not confirmed customer
$customer->sendNewAccountEmail('confirmed', '', $storeId);
}
}
Edited the confirmAction() in AccountController.php as follows:
public function confirmAction()
{
$session = $this->_getSession();
if ($session->isLoggedIn()) {
$this->_getSession()->logout()->regenerateSessionId();
}
try {
$id = $this->getRequest()->getParam('id', false);
$key = $this->getRequest()->getParam('key', false);
$backUrl = $this->getRequest()->getParam('back_url', false);
if (empty($id) || empty($key)) {
throw new Exception($this->__('Bad request.'));
}
// load customer by id (try/catch in case if it throws exceptions)
try {
$customer = $this->_getModel('customer/customer')->load($id);
if ((!$customer) || (!$customer->getId())) {
throw new Exception('Failed to load customer by id.');
}
}
catch (Exception $e) {
throw new Exception($this->__('Wrong customer account specified.'));
}
// check if it is inactive
if ($customer->getConfirmation()) {
if ($customer->getConfirmation() !== $key) {
throw new Exception($this->__('Wrong confirmation key.'));
}
// activate customer
try {
$customer->setConfirmation(null);
$customer->save();
}
catch (Exception $e) {
throw new Exception($this->__('Failed to confirm customer account.'));
}
$session->renewSession();
// log in and send greeting email, then die happy
$session->setCustomerAsLoggedIn($customer);
$successUrl = $this->_welcomeCustomer($customer, true);
$customUrl = $this->_redirectSuccess(Mage::getBaseUrl());
$this->_redirectSuccess($customUrl ? $customUrl : $successUrl);
return;
}
// die happy
$this->_redirectSuccess($this->_getUrl('*/*/index', array('_secure' => true)));
return;
}
catch (Exception $e) {
// die unhappy
$this->_getSession()->addError($e->getMessage());
$this->_redirectError($this->_getUrl('*/*/index', array('_secure' => true)));
return;
}
}
$customUrl contains URL where I need to redirect the customer after clicking the confirmation link and confirm their account as well.
Best Answer
You can make the password input in the registration and checkout process as a hidden input and have an algorithm that generates random values for it.
For example at registration you have these fields for passwords
and
Turn them into this:
and