I want to generate random number or string in forgot password template? I used directly "getRandomString(6)" that print same thing? I did not get how should i change?

  • Try this: $customer.generatePassword(6). Not tested – Abdul Mar 14 '18 at 7:59
  • It does not work. – Ankush Deora Mar 14 '18 at 8:48

In Magento Way, You can use Follwoing code for generate random string.

$randomString = Mage::helper('core')->getRandomString($length = 6);

If you want to put it in Password field in form.use the below

<?php $password = Mage::helper('core')->getRandomString($length = 7)?>

<input type="hidden" name="password" id="password" title="<?php echo $this->__('Password') ?>" class="input-text required-entry validate-password" value="<?php echo $password?>"  />
| improve this answer | |
  • I want to generate a verification code as a token in forgot password email...how can i generate that code? – Ankush Deora Mar 14 '18 at 11:03
  • So you want it in php code,correct? – Nagaraj Juro Mar 14 '18 at 11:05

An other possible script in magento way for a link hash is:

$key = Mage::helper('core')->getRandomString($length = 12);;
$uniqid = uniqid(mt_rand(), true);
$hash = md5($key . $uniqid);
return $hash;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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