如何增加WHMCS中生成的服务密码字符

时间:2018-11-07 08:07:20

标签: whmcs

我有一个自定义的WHMCS设置模块。用户创建订单时,然后生成服务密码: Password on Manage Orders page 此密码包含10个(字母数字)或14个(字母数字和特殊字符)字符。从管理面板,我只能增加它的复杂性。 如何截取密码以增加字符数?

已编辑

我尝试使用'PreModuleCreate'挂钩,但未触发(其他挂钩已触发)。

1 个答案:

答案 0 :(得分:0)

您可以挂钩PreModuleCreate来覆盖系统生成的密码。

  

PreModuleCreate在为服务运行模块创建功能之前执行。

一个简单的例子:

add_hook('PreModuleCreate', 1, function($vars) {
    $system_generated_password = $vars['password']; //this is the system generated password

    //lets generate a quick 20 character string
    $ch_lenght = 20;//length of the string/password
    $characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()";
    $new_password = array();
    $ch_length = strlen($characters) - 1;
    for ($i = 0; $i < $ch_lenght ; $i++) {
        $n = rand(0, $ch_length);
        $new_password[] = $characters[$n];
    }

    $new_password = implode($new_password); //turn the array into a string

    //now override default system generated password with the new string
    $vars['password'] = $new_password;

    return $vars;
}

以上代码将生成一个随机的20个字符串,并将其设置为该服务的新密码,而不是系统生成的密码。根据需要进行更改。

Here is a list of available module parameters

If you are not sure of how to add your hook, have a look at here