Jump to content

Generate Random Password - API Order Form


DavidBee

Recommended Posts

Hello WHMCS Forums!

 

I currently have a working order form using the API but I am trying to cut down the amount of required fields so would like to hide the password field and randomly generate passwords for the client area login.

 

Can anyone point me in the correct direction please?

 

Thanks

Link to comment
Share on other sites

I would also like this. I think it would be even better if WHMCS could completely remove the password fields from the order form as default. It would be much better to have the password get autogenerated by WHMCS and then sent to client after ordering. I think thats generally more secure, because clients often do not make strong enough passwords, also it is like you say a extra field, and I think it would be better to cut down on this for sales ...

Link to comment
Share on other sites

What you can do is generated a random password using php and then input the password into hidden fields and remove the normal password fields from the viewcart.tpl.

 

At the top of the template add or you can use something similar to generate a random password:

{php}
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";	
$size = strlen( $chars );
$generated_password = "";
for( $i = 0; $i < 12; $i++ ) {
 $generated_password .= $chars[ rand( 0, $size - 1 ) ];
}
$this->assign('generated_password',$generated_password);

{/php}

 

You can add the following hidden fields near the submit button.

{if !$loggedin}
<input type="hidden" name="password" value="{$generated_password}" />
<input type="hidden" name="password2" value="{$generated_password}" />
{/if}

 

Then remove these two fields from the form and the password strength field as well and a random client area password will be generated.

Link to comment
Share on other sites

The API does allow you to create clients and pass it a password for the new client, make you are passing the parameter as password2 and not password. If that isn't your issue, if you post your code here, someone may be able to see what is wrong with it.

Link to comment
Share on other sites

We here is the what I am trying to use to generate a random password.

 

 

function generate_password($len =  {  
$chars = str_split('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#');  


for($i=0; $i < $len; $i++)  
$password .= $chars[rand(1, $sizeof($chars)) -1];  
return $password;  
}  

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated