How to generate random password for customer in Magento2?How to generate random password for new customer while creating account in magento?password error after upgrade to 1.9.1Magento 2.1 - Set customer password in backendBest Way to Load a Custom Model in Magento 2Remove fields from registration formMagento 2 : How to update customer password by customer repositoryForm is not displayed on panel admin Magento 2How to generate random password for new customer while creating account in magento 2?Magento 2 How to disable price from orders, customer account and order view if custom module is enabled?

Is it feasible to get a hash collision for CRC32, MD-5 and SHA-1 on one file?

how do companies get money from being listed publicly

What is a good class if we remove subclasses?

The cat ate your input again!

How to remove ambiguity: "... lives in the city of H, the capital of the province of NS, WHERE the unemployment rate is ..."?

Not going forward with internship interview process

Is it legal for a company to enter an agreement not to hire employees from another company?

How to divide item stack in MC PE?

How does proof assistant organize knowledge?

How are you supposed to know the strumming pattern for a song from the "chord sheet music"?

Is God unknowable?

Is this n-speak?

Is there a command to install basic applications on Ubuntu 16.04?

Submitting a new paper just after another was accepted by the same journal

Is this curved text blend possible in Illustrator?

When were the tantalum capacitors first used in computing?

Plotting octahedron inside the sphere and sphere inside the cube

Is there a standardised way to check fake news?

A continuous water "planet" ring around a star

How would timezones work on a planet 100 times the size of our Earth

Why is the result of ('b'+'a'+ + 'a' + 'a').toLowerCase() 'banana'?

Loading military units into ships optimally, using backtracking

Solution to German Tank Problem

On the Rømer experiments and the speed of light



How to generate random password for customer in Magento2?


How to generate random password for new customer while creating account in magento?password error after upgrade to 1.9.1Magento 2.1 - Set customer password in backendBest Way to Load a Custom Model in Magento 2Remove fields from registration formMagento 2 : How to update customer password by customer repositoryForm is not displayed on panel admin Magento 2How to generate random password for new customer while creating account in magento 2?Magento 2 How to disable price from orders, customer account and order view if custom module is enabled?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















We had a method to generate the random passwords for the customers in Magento1 in following class.



appcodecoreMageCustomerModelCustomer.php


method >>



 /**
* Retrieve random password
*
* @param int $length
* @return string
*/
public function generatePassword($length = 8)

$chars = Mage_Core_Helper_Data::CHARS_PASSWORD_LOWERS
. Mage_Core_Helper_Data::CHARS_PASSWORD_UPPERS
. Mage_Core_Helper_Data::CHARS_PASSWORD_DIGITS
. Mage_Core_Helper_Data::CHARS_PASSWORD_SPECIALS;
return Mage::helper('core')->getRandomString($length, $chars);



What is the similar method in Magento2?










share|improve this question
































    1















    We had a method to generate the random passwords for the customers in Magento1 in following class.



    appcodecoreMageCustomerModelCustomer.php


    method >>



     /**
    * Retrieve random password
    *
    * @param int $length
    * @return string
    */
    public function generatePassword($length = 8)

    $chars = Mage_Core_Helper_Data::CHARS_PASSWORD_LOWERS
    . Mage_Core_Helper_Data::CHARS_PASSWORD_UPPERS
    . Mage_Core_Helper_Data::CHARS_PASSWORD_DIGITS
    . Mage_Core_Helper_Data::CHARS_PASSWORD_SPECIALS;
    return Mage::helper('core')->getRandomString($length, $chars);



    What is the similar method in Magento2?










    share|improve this question




























      1












      1








      1








      We had a method to generate the random passwords for the customers in Magento1 in following class.



      appcodecoreMageCustomerModelCustomer.php


      method >>



       /**
      * Retrieve random password
      *
      * @param int $length
      * @return string
      */
      public function generatePassword($length = 8)

      $chars = Mage_Core_Helper_Data::CHARS_PASSWORD_LOWERS
      . Mage_Core_Helper_Data::CHARS_PASSWORD_UPPERS
      . Mage_Core_Helper_Data::CHARS_PASSWORD_DIGITS
      . Mage_Core_Helper_Data::CHARS_PASSWORD_SPECIALS;
      return Mage::helper('core')->getRandomString($length, $chars);



      What is the similar method in Magento2?










      share|improve this question
















      We had a method to generate the random passwords for the customers in Magento1 in following class.



      appcodecoreMageCustomerModelCustomer.php


      method >>



       /**
      * Retrieve random password
      *
      * @param int $length
      * @return string
      */
      public function generatePassword($length = 8)

      $chars = Mage_Core_Helper_Data::CHARS_PASSWORD_LOWERS
      . Mage_Core_Helper_Data::CHARS_PASSWORD_UPPERS
      . Mage_Core_Helper_Data::CHARS_PASSWORD_DIGITS
      . Mage_Core_Helper_Data::CHARS_PASSWORD_SPECIALS;
      return Mage::helper('core')->getRandomString($length, $chars);



      What is the similar method in Magento2?







      magento-2.1 customer password






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 1 at 10:22









      Mohit Rane

      1,20718 bronze badges




      1,20718 bronze badges










      asked Jul 25 '17 at 8:53









      MukeshMukesh

      9551 gold badge15 silver badges45 bronze badges




      9551 gold badge15 silver badges45 bronze badges























          5 Answers
          5






          active

          oldest

          votes


















          2














          I used the following code to generate the passwords for the customers.



          <?php
          namespace MukCommonHelper;

          class CustomerPasswordGeneration extends MagentoFrameworkAppHelperAbstractHelper
          {

          /**
          * @var MagentoFrameworkMathRandom
          */
          protected $mathRandom;

          public function __construct(
          Context $context,
          MagentoFrameworkMathRandom $mathRandom
          )
          $this->mathRandom = $mathRandom;
          parent::__construct($context);


          /**
          * Retrieve random password
          *
          * @param int $length
          * @return string
          */
          public function generatePassword($length = 10)

          $chars = MagentoFrameworkMathRandom::CHARS_LOWERS
          . MagentoFrameworkMathRandom::CHARS_UPPERS
          . MagentoFrameworkMathRandom::CHARS_DIGITS;

          return $password = $this->mathRandom->getRandomString($length, $chars);






          share|improve this answer
































            1














            Magento use function like this in the setup script



            vendor/magento/magento2-base/setup/src/Magento/Setup/Model/AdminAccount.php



             /**
            * Generate password string
            *
            * @return string
            */
            protected function generatePassword()

            return $this->encryptor->getHash($this->data[self::KEY_PASSWORD], true);






            share|improve this answer




















            • 1





              I know about this. But in my case I am not passing self::KEY_PASSWORD to generate the password.

              – Mukesh
              Jul 25 '17 at 9:04






            • 1





              also check Magento/Customer/Model/AccountManagement.php I think you have to generate password string by your own if you have not it

              – bxN5
              Jul 25 '17 at 9:13











            • yes, for random strings I can use class MagentoFrameworkMathRandom

              – Mukesh
              Jul 25 '17 at 11:10


















            1














            I have made one custom url (new custom controller) to generate customer's password .



            <?php
            namespace CompanyModuleControllerIndex;

            use MagentoFrameworkEncryptionEncryptorInterface as Encryptor;

            class Index extends MagentoFrameworkAppActionAction

            protected $_resultPageFactory;
            protected $_indexer;

            public function __construct(MagentoFrameworkAppActionContext $context,Encryptor $encryptor, MagentoFrameworkViewResultPageFactory $resultPageFactory)
            $this->_resultPageFactory = $resultPageFactory;
            $this->encryptor = $encryptor;
            return parent::__construct($context);


            public function execute()
            $password = '123456'; //or you can use php random function rand() to generate string
            $hash = $this->encryptor->hash($password);
            $newhash = $this->encryptor->getHash($password, true);
            echo $newhash; // this will be customer's new password, which need to store in 'password_hash' column of "customer_entity" db table.




            you can integrate same code in your functional method / file .






            share|improve this answer


































              0














              I used this code simply and got result



               <?php 
              function generateRandomString($length)
              $characters =
              '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@#$%&';
              $charactersLength = strlen($characters);
              $randomString = '';
              for ($i = 0; $i < $length; $i++)
              $randomString .= $characters[rand(0, $charactersLength - 1)];

              return $randomString;

              ?>

              <?php echo generateRandomString(5); ?>





              share|improve this answer
































                0














                I used the following method



                 <?php

                function randomPassword()

                $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
                $password = [];
                $alphaLength = strlen($alphabet) - 1;
                for ($i = 0; $i < 8; $i++)
                $n = rand(0, $alphaLength);
                $password[] = $alphabet[$n];

                return implode($password);


                randomPassword();





                share|improve this answer





























                  Your Answer








                  StackExchange.ready(function()
                  var channelOptions =
                  tags: "".split(" "),
                  id: "479"
                  ;
                  initTagRenderer("".split(" "), "".split(" "), channelOptions);

                  StackExchange.using("externalEditor", function()
                  // Have to fire editor after snippets, if snippets enabled
                  if (StackExchange.settings.snippets.snippetsEnabled)
                  StackExchange.using("snippets", function()
                  createEditor();
                  );

                  else
                  createEditor();

                  );

                  function createEditor()
                  StackExchange.prepareEditor(
                  heartbeatType: 'answer',
                  autoActivateHeartbeat: false,
                  convertImagesToLinks: false,
                  noModals: true,
                  showLowRepImageUploadWarning: true,
                  reputationToPostImages: null,
                  bindNavPrevention: true,
                  postfix: "",
                  imageUploader:
                  brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                  contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                  allowUrls: true
                  ,
                  onDemand: true,
                  discardSelector: ".discard-answer"
                  ,immediatelyShowMarkdownHelp:true
                  );



                  );













                  draft saved

                  draft discarded


















                  StackExchange.ready(
                  function ()
                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f186309%2fhow-to-generate-random-password-for-customer-in-magento2%23new-answer', 'question_page');

                  );

                  Post as a guest















                  Required, but never shown

























                  5 Answers
                  5






                  active

                  oldest

                  votes








                  5 Answers
                  5






                  active

                  oldest

                  votes









                  active

                  oldest

                  votes






                  active

                  oldest

                  votes









                  2














                  I used the following code to generate the passwords for the customers.



                  <?php
                  namespace MukCommonHelper;

                  class CustomerPasswordGeneration extends MagentoFrameworkAppHelperAbstractHelper
                  {

                  /**
                  * @var MagentoFrameworkMathRandom
                  */
                  protected $mathRandom;

                  public function __construct(
                  Context $context,
                  MagentoFrameworkMathRandom $mathRandom
                  )
                  $this->mathRandom = $mathRandom;
                  parent::__construct($context);


                  /**
                  * Retrieve random password
                  *
                  * @param int $length
                  * @return string
                  */
                  public function generatePassword($length = 10)

                  $chars = MagentoFrameworkMathRandom::CHARS_LOWERS
                  . MagentoFrameworkMathRandom::CHARS_UPPERS
                  . MagentoFrameworkMathRandom::CHARS_DIGITS;

                  return $password = $this->mathRandom->getRandomString($length, $chars);






                  share|improve this answer





























                    2














                    I used the following code to generate the passwords for the customers.



                    <?php
                    namespace MukCommonHelper;

                    class CustomerPasswordGeneration extends MagentoFrameworkAppHelperAbstractHelper
                    {

                    /**
                    * @var MagentoFrameworkMathRandom
                    */
                    protected $mathRandom;

                    public function __construct(
                    Context $context,
                    MagentoFrameworkMathRandom $mathRandom
                    )
                    $this->mathRandom = $mathRandom;
                    parent::__construct($context);


                    /**
                    * Retrieve random password
                    *
                    * @param int $length
                    * @return string
                    */
                    public function generatePassword($length = 10)

                    $chars = MagentoFrameworkMathRandom::CHARS_LOWERS
                    . MagentoFrameworkMathRandom::CHARS_UPPERS
                    . MagentoFrameworkMathRandom::CHARS_DIGITS;

                    return $password = $this->mathRandom->getRandomString($length, $chars);






                    share|improve this answer



























                      2












                      2








                      2







                      I used the following code to generate the passwords for the customers.



                      <?php
                      namespace MukCommonHelper;

                      class CustomerPasswordGeneration extends MagentoFrameworkAppHelperAbstractHelper
                      {

                      /**
                      * @var MagentoFrameworkMathRandom
                      */
                      protected $mathRandom;

                      public function __construct(
                      Context $context,
                      MagentoFrameworkMathRandom $mathRandom
                      )
                      $this->mathRandom = $mathRandom;
                      parent::__construct($context);


                      /**
                      * Retrieve random password
                      *
                      * @param int $length
                      * @return string
                      */
                      public function generatePassword($length = 10)

                      $chars = MagentoFrameworkMathRandom::CHARS_LOWERS
                      . MagentoFrameworkMathRandom::CHARS_UPPERS
                      . MagentoFrameworkMathRandom::CHARS_DIGITS;

                      return $password = $this->mathRandom->getRandomString($length, $chars);






                      share|improve this answer













                      I used the following code to generate the passwords for the customers.



                      <?php
                      namespace MukCommonHelper;

                      class CustomerPasswordGeneration extends MagentoFrameworkAppHelperAbstractHelper
                      {

                      /**
                      * @var MagentoFrameworkMathRandom
                      */
                      protected $mathRandom;

                      public function __construct(
                      Context $context,
                      MagentoFrameworkMathRandom $mathRandom
                      )
                      $this->mathRandom = $mathRandom;
                      parent::__construct($context);


                      /**
                      * Retrieve random password
                      *
                      * @param int $length
                      * @return string
                      */
                      public function generatePassword($length = 10)

                      $chars = MagentoFrameworkMathRandom::CHARS_LOWERS
                      . MagentoFrameworkMathRandom::CHARS_UPPERS
                      . MagentoFrameworkMathRandom::CHARS_DIGITS;

                      return $password = $this->mathRandom->getRandomString($length, $chars);







                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Jul 26 '17 at 5:39









                      MukeshMukesh

                      9551 gold badge15 silver badges45 bronze badges




                      9551 gold badge15 silver badges45 bronze badges


























                          1














                          Magento use function like this in the setup script



                          vendor/magento/magento2-base/setup/src/Magento/Setup/Model/AdminAccount.php



                           /**
                          * Generate password string
                          *
                          * @return string
                          */
                          protected function generatePassword()

                          return $this->encryptor->getHash($this->data[self::KEY_PASSWORD], true);






                          share|improve this answer




















                          • 1





                            I know about this. But in my case I am not passing self::KEY_PASSWORD to generate the password.

                            – Mukesh
                            Jul 25 '17 at 9:04






                          • 1





                            also check Magento/Customer/Model/AccountManagement.php I think you have to generate password string by your own if you have not it

                            – bxN5
                            Jul 25 '17 at 9:13











                          • yes, for random strings I can use class MagentoFrameworkMathRandom

                            – Mukesh
                            Jul 25 '17 at 11:10















                          1














                          Magento use function like this in the setup script



                          vendor/magento/magento2-base/setup/src/Magento/Setup/Model/AdminAccount.php



                           /**
                          * Generate password string
                          *
                          * @return string
                          */
                          protected function generatePassword()

                          return $this->encryptor->getHash($this->data[self::KEY_PASSWORD], true);






                          share|improve this answer




















                          • 1





                            I know about this. But in my case I am not passing self::KEY_PASSWORD to generate the password.

                            – Mukesh
                            Jul 25 '17 at 9:04






                          • 1





                            also check Magento/Customer/Model/AccountManagement.php I think you have to generate password string by your own if you have not it

                            – bxN5
                            Jul 25 '17 at 9:13











                          • yes, for random strings I can use class MagentoFrameworkMathRandom

                            – Mukesh
                            Jul 25 '17 at 11:10













                          1












                          1








                          1







                          Magento use function like this in the setup script



                          vendor/magento/magento2-base/setup/src/Magento/Setup/Model/AdminAccount.php



                           /**
                          * Generate password string
                          *
                          * @return string
                          */
                          protected function generatePassword()

                          return $this->encryptor->getHash($this->data[self::KEY_PASSWORD], true);






                          share|improve this answer













                          Magento use function like this in the setup script



                          vendor/magento/magento2-base/setup/src/Magento/Setup/Model/AdminAccount.php



                           /**
                          * Generate password string
                          *
                          * @return string
                          */
                          protected function generatePassword()

                          return $this->encryptor->getHash($this->data[self::KEY_PASSWORD], true);







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jul 25 '17 at 9:00









                          bxN5bxN5

                          1663 bronze badges




                          1663 bronze badges










                          • 1





                            I know about this. But in my case I am not passing self::KEY_PASSWORD to generate the password.

                            – Mukesh
                            Jul 25 '17 at 9:04






                          • 1





                            also check Magento/Customer/Model/AccountManagement.php I think you have to generate password string by your own if you have not it

                            – bxN5
                            Jul 25 '17 at 9:13











                          • yes, for random strings I can use class MagentoFrameworkMathRandom

                            – Mukesh
                            Jul 25 '17 at 11:10












                          • 1





                            I know about this. But in my case I am not passing self::KEY_PASSWORD to generate the password.

                            – Mukesh
                            Jul 25 '17 at 9:04






                          • 1





                            also check Magento/Customer/Model/AccountManagement.php I think you have to generate password string by your own if you have not it

                            – bxN5
                            Jul 25 '17 at 9:13











                          • yes, for random strings I can use class MagentoFrameworkMathRandom

                            – Mukesh
                            Jul 25 '17 at 11:10







                          1




                          1





                          I know about this. But in my case I am not passing self::KEY_PASSWORD to generate the password.

                          – Mukesh
                          Jul 25 '17 at 9:04





                          I know about this. But in my case I am not passing self::KEY_PASSWORD to generate the password.

                          – Mukesh
                          Jul 25 '17 at 9:04




                          1




                          1





                          also check Magento/Customer/Model/AccountManagement.php I think you have to generate password string by your own if you have not it

                          – bxN5
                          Jul 25 '17 at 9:13





                          also check Magento/Customer/Model/AccountManagement.php I think you have to generate password string by your own if you have not it

                          – bxN5
                          Jul 25 '17 at 9:13













                          yes, for random strings I can use class MagentoFrameworkMathRandom

                          – Mukesh
                          Jul 25 '17 at 11:10





                          yes, for random strings I can use class MagentoFrameworkMathRandom

                          – Mukesh
                          Jul 25 '17 at 11:10











                          1














                          I have made one custom url (new custom controller) to generate customer's password .



                          <?php
                          namespace CompanyModuleControllerIndex;

                          use MagentoFrameworkEncryptionEncryptorInterface as Encryptor;

                          class Index extends MagentoFrameworkAppActionAction

                          protected $_resultPageFactory;
                          protected $_indexer;

                          public function __construct(MagentoFrameworkAppActionContext $context,Encryptor $encryptor, MagentoFrameworkViewResultPageFactory $resultPageFactory)
                          $this->_resultPageFactory = $resultPageFactory;
                          $this->encryptor = $encryptor;
                          return parent::__construct($context);


                          public function execute()
                          $password = '123456'; //or you can use php random function rand() to generate string
                          $hash = $this->encryptor->hash($password);
                          $newhash = $this->encryptor->getHash($password, true);
                          echo $newhash; // this will be customer's new password, which need to store in 'password_hash' column of "customer_entity" db table.




                          you can integrate same code in your functional method / file .






                          share|improve this answer































                            1














                            I have made one custom url (new custom controller) to generate customer's password .



                            <?php
                            namespace CompanyModuleControllerIndex;

                            use MagentoFrameworkEncryptionEncryptorInterface as Encryptor;

                            class Index extends MagentoFrameworkAppActionAction

                            protected $_resultPageFactory;
                            protected $_indexer;

                            public function __construct(MagentoFrameworkAppActionContext $context,Encryptor $encryptor, MagentoFrameworkViewResultPageFactory $resultPageFactory)
                            $this->_resultPageFactory = $resultPageFactory;
                            $this->encryptor = $encryptor;
                            return parent::__construct($context);


                            public function execute()
                            $password = '123456'; //or you can use php random function rand() to generate string
                            $hash = $this->encryptor->hash($password);
                            $newhash = $this->encryptor->getHash($password, true);
                            echo $newhash; // this will be customer's new password, which need to store in 'password_hash' column of "customer_entity" db table.




                            you can integrate same code in your functional method / file .






                            share|improve this answer





























                              1












                              1








                              1







                              I have made one custom url (new custom controller) to generate customer's password .



                              <?php
                              namespace CompanyModuleControllerIndex;

                              use MagentoFrameworkEncryptionEncryptorInterface as Encryptor;

                              class Index extends MagentoFrameworkAppActionAction

                              protected $_resultPageFactory;
                              protected $_indexer;

                              public function __construct(MagentoFrameworkAppActionContext $context,Encryptor $encryptor, MagentoFrameworkViewResultPageFactory $resultPageFactory)
                              $this->_resultPageFactory = $resultPageFactory;
                              $this->encryptor = $encryptor;
                              return parent::__construct($context);


                              public function execute()
                              $password = '123456'; //or you can use php random function rand() to generate string
                              $hash = $this->encryptor->hash($password);
                              $newhash = $this->encryptor->getHash($password, true);
                              echo $newhash; // this will be customer's new password, which need to store in 'password_hash' column of "customer_entity" db table.




                              you can integrate same code in your functional method / file .






                              share|improve this answer















                              I have made one custom url (new custom controller) to generate customer's password .



                              <?php
                              namespace CompanyModuleControllerIndex;

                              use MagentoFrameworkEncryptionEncryptorInterface as Encryptor;

                              class Index extends MagentoFrameworkAppActionAction

                              protected $_resultPageFactory;
                              protected $_indexer;

                              public function __construct(MagentoFrameworkAppActionContext $context,Encryptor $encryptor, MagentoFrameworkViewResultPageFactory $resultPageFactory)
                              $this->_resultPageFactory = $resultPageFactory;
                              $this->encryptor = $encryptor;
                              return parent::__construct($context);


                              public function execute()
                              $password = '123456'; //or you can use php random function rand() to generate string
                              $hash = $this->encryptor->hash($password);
                              $newhash = $this->encryptor->getHash($password, true);
                              echo $newhash; // this will be customer's new password, which need to store in 'password_hash' column of "customer_entity" db table.




                              you can integrate same code in your functional method / file .







                              share|improve this answer














                              share|improve this answer



                              share|improve this answer








                              edited Jul 25 '17 at 10:17









                              simple guy

                              1,0492 gold badges15 silver badges43 bronze badges




                              1,0492 gold badges15 silver badges43 bronze badges










                              answered Jul 25 '17 at 9:27









                              LuckyLucky

                              1221 silver badge10 bronze badges




                              1221 silver badge10 bronze badges
























                                  0














                                  I used this code simply and got result



                                   <?php 
                                  function generateRandomString($length)
                                  $characters =
                                  '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@#$%&';
                                  $charactersLength = strlen($characters);
                                  $randomString = '';
                                  for ($i = 0; $i < $length; $i++)
                                  $randomString .= $characters[rand(0, $charactersLength - 1)];

                                  return $randomString;

                                  ?>

                                  <?php echo generateRandomString(5); ?>





                                  share|improve this answer





























                                    0














                                    I used this code simply and got result



                                     <?php 
                                    function generateRandomString($length)
                                    $characters =
                                    '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@#$%&';
                                    $charactersLength = strlen($characters);
                                    $randomString = '';
                                    for ($i = 0; $i < $length; $i++)
                                    $randomString .= $characters[rand(0, $charactersLength - 1)];

                                    return $randomString;

                                    ?>

                                    <?php echo generateRandomString(5); ?>





                                    share|improve this answer



























                                      0












                                      0








                                      0







                                      I used this code simply and got result



                                       <?php 
                                      function generateRandomString($length)
                                      $characters =
                                      '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@#$%&';
                                      $charactersLength = strlen($characters);
                                      $randomString = '';
                                      for ($i = 0; $i < $length; $i++)
                                      $randomString .= $characters[rand(0, $charactersLength - 1)];

                                      return $randomString;

                                      ?>

                                      <?php echo generateRandomString(5); ?>





                                      share|improve this answer













                                      I used this code simply and got result



                                       <?php 
                                      function generateRandomString($length)
                                      $characters =
                                      '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@#$%&';
                                      $charactersLength = strlen($characters);
                                      $randomString = '';
                                      for ($i = 0; $i < $length; $i++)
                                      $randomString .= $characters[rand(0, $charactersLength - 1)];

                                      return $randomString;

                                      ?>

                                      <?php echo generateRandomString(5); ?>






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Aug 2 '18 at 9:51









                                      SUBBULAKSHMI GSUBBULAKSHMI G

                                      809 bronze badges




                                      809 bronze badges
























                                          0














                                          I used the following method



                                           <?php

                                          function randomPassword()

                                          $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
                                          $password = [];
                                          $alphaLength = strlen($alphabet) - 1;
                                          for ($i = 0; $i < 8; $i++)
                                          $n = rand(0, $alphaLength);
                                          $password[] = $alphabet[$n];

                                          return implode($password);


                                          randomPassword();





                                          share|improve this answer































                                            0














                                            I used the following method



                                             <?php

                                            function randomPassword()

                                            $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
                                            $password = [];
                                            $alphaLength = strlen($alphabet) - 1;
                                            for ($i = 0; $i < 8; $i++)
                                            $n = rand(0, $alphaLength);
                                            $password[] = $alphabet[$n];

                                            return implode($password);


                                            randomPassword();





                                            share|improve this answer





























                                              0












                                              0








                                              0







                                              I used the following method



                                               <?php

                                              function randomPassword()

                                              $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
                                              $password = [];
                                              $alphaLength = strlen($alphabet) - 1;
                                              for ($i = 0; $i < 8; $i++)
                                              $n = rand(0, $alphaLength);
                                              $password[] = $alphabet[$n];

                                              return implode($password);


                                              randomPassword();





                                              share|improve this answer















                                              I used the following method



                                               <?php

                                              function randomPassword()

                                              $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
                                              $password = [];
                                              $alphaLength = strlen($alphabet) - 1;
                                              for ($i = 0; $i < 8; $i++)
                                              $n = rand(0, $alphaLength);
                                              $password[] = $alphabet[$n];

                                              return implode($password);


                                              randomPassword();






                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited Aug 5 at 6:43

























                                              answered Aug 1 at 10:00









                                              Arshad SyedArshad Syed

                                              488 bronze badges




                                              488 bronze badges






























                                                  draft saved

                                                  draft discarded
















































                                                  Thanks for contributing an answer to Magento Stack Exchange!


                                                  • Please be sure to answer the question. Provide details and share your research!

                                                  But avoid


                                                  • Asking for help, clarification, or responding to other answers.

                                                  • Making statements based on opinion; back them up with references or personal experience.

                                                  To learn more, see our tips on writing great answers.




                                                  draft saved


                                                  draft discarded














                                                  StackExchange.ready(
                                                  function ()
                                                  StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f186309%2fhow-to-generate-random-password-for-customer-in-magento2%23new-answer', 'question_page');

                                                  );

                                                  Post as a guest















                                                  Required, but never shown





















































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown

































                                                  Required, but never shown














                                                  Required, but never shown












                                                  Required, but never shown







                                                  Required, but never shown







                                                  Popular posts from this blog

                                                  Grendel Contents Story Scholarship Depictions Notes References Navigation menu10.1093/notesj/gjn112Berserkeree

                                                  Area configuration aggregation error after install Porto themeMagento 2.1 CE Installed but front/backend not loading/workingCSS not loading on page within Magento 2 pageCannot install module in Magento 2no commands defined in the “setup” namespace. in Magento2Magento 2: Static files are present but shows 404Why do i have to always run the commands to clean cache in Magento 2.1.8?Failure reason: 'Unable to unserialize value.'Error 500 after magento migrationIn production mode the site does not loadMagento 2 : Error 500 after installing

                                                  Middle Expansion Olielle Resaix Definition: Uttering songs of triumph shouting with joy triumphant exulting Sejunction Journal 붙다 달 고급 품목 외출 The stretch trades the screeching tin. Definition: The act of speaking with a drawl a drawl Cough Sand Definition: An uproar a quarrel a noisy outbreak Shake Iron Publicize Horse House Baby 사과 Resaix Flaggy Jelly Temporary Unequaled Puppet A drop in the bucket Shrew 성격 회원 성질 미팅 The burn frames the tacky quality. Materialistic The smoke reduces the way. Yammoe Nondescript Cheek 얼굴 배 약하다 날리다 타다 The illegal country shows the iron. Help Rule Drearien Smoke Teaching Meaty Wasp Abraham Lincoln Jaws 진심 수리하다 Size Cork Idea Convert Think Lark John Lennon 거울 청소 군 추천하다 아이스크림