leeego Posted July 29, 2013 Share Posted July 29, 2013 hello! i would like to auto-generate a password for the user during checkout. guest checkout will be disabled and i'm using the one-page-checkout. i found the passwdGen function inside Tools.php, but to be honest i don't know how to integrate it to the the checkout process in a safe way. any ideas? 1 Link to comment Share on other sites More sharing options...
PascalVG Posted July 29, 2013 Share Posted July 29, 2013 (edited) Hi Leeego, What you can do: (Example in files of PS 1.5.4.1) edit file: /controllers/front/AuthController.php (Make backup, just in case) find function: public function initContent() and scroll down until you find the following code: (And add the two lines just above it) $randompassword= Tools::passwdGen(8); // ADD THIS LINE $this->context->smarty->assign('randompassword', $randompassword ); // ADD THIS LINE if ($this->ajax) { // Call a hook to display more information on form $this->context->smarty->assign(array( 'PS_REGISTRATION_PROCESS_TYPE' => Configuration::get('PS_REGISTRATION_PROCESS_TYPE'), 'genders' => Gender::getGenders() )); $return = array( 'hasError' => !empty($this->errors), 'errors' => $this->errors, 'page' => $this->context->smarty->fetch(_PS_THEME_DIR_.'authentication.tpl'), 'token' => Tools::getToken(false) ); die(Tools::jsonEncode($return)); } $this->setTemplate(_PS_THEME_DIR_.'authentication.tpl'); } and save file. The edit file: /themes/<your theme folder>/authentication.tpl (make backup again) and find the following code: (easiest by searching for "Five characters" with CTRL-F) <p class="required password"> <label for="passwd">{l s='Password'} <sup>*</sup></label> <input type="password" class="text" name="passwd" id="passwd" value="{$randompassword}" readonly /> <span class="form_info">{l s='(Five characters minimum)'}</span> </p> add the red piece of code. Save file and try if it works. What it does is, it generates a random string (consisting of a substring of a-z A-Z 0-9 ) of length 8 using the tools function: Tools::passwdGen(8) (you can change that of course to a longer or shorter password as desired) Then it adds it as a default value to the input field in the create customer page and makes this field read only, so that the user cannot change the value anymore. Hope this helps, pascal Edited July 29, 2013 by PascalVG (see edit history) 1 Link to comment Share on other sites More sharing options...
leeego Posted July 30, 2013 Author Share Posted July 30, 2013 hi pascal, thanks for all your input! i didn't know it was so easy to make use of the passwdGen function however, i'm slightly confused about which controller file i should put your code into. i know you suggested AuthController.php, but as far as i can see, this controller is not used when the user is on the checkout page but when he's on the login page for his account. i tried to find the correct place to put it inside OrderOpcController.php, but don't know where. 1 Link to comment Share on other sites More sharing options...
leeego Posted July 30, 2013 Author Share Posted July 30, 2013 sorry, forget about my previous post. i must have been stupid to not see the answer myself so, i did it the following way: i've put the following two lines in OrderOpcController.php (as an override) inside the function initContent $randompassword = Tools::passwdGen(8); $this->context->smarty->assign('randompassword', $randompassword); i then changed the password field in order-opc-new-account.tpl to a hidden field like this: <input type="hidden" id="passwd" name="passwd" value="{$randompassword}"> thanks again for your help! 1 Link to comment Share on other sites More sharing options...
PascalVG Posted July 30, 2013 Share Posted July 30, 2013 Hi Leeego, Glad it works for you. 2 Small checks: - Do you need to make the field read-only or is that working like that already? - My example above added a default, random, non-editable password to the sign-up screen where a new customer adds his credentials like Email address, name etc. Where exactly does your code add it? (Just asking, to make it fully clear for others re-using this topic for solving their future problem :-) ) Anyway, I mark this Topic solved :-) pascal Link to comment Share on other sites More sharing options...
leeego Posted July 30, 2013 Author Share Posted July 30, 2013 (edited) The input field has a type of hidden, thus the readonly attribute is not needed and actually not allowed. In my shop, you can only create an account when you order for the first time. You cannot go to the my-account page and create an account yourself. Thus, I only added the random password during one-page-checkout (as mentioned, in the template order-opc-new-account.tpl). Edited July 30, 2013 by leeego (see edit history) Link to comment Share on other sites More sharing options...
PascalVG Posted July 30, 2013 Share Posted July 30, 2013 Thanks for the additional info, Leego! Good luck with your shop! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now