此命令可用于针对 WHMCS 中的注册用户验证电子邮件地址和密码。
如果电子邮件地址有效且密码正确,则会话将作为创建密码哈希的一部分启动。此会话可用于远程登录(见下文),但如果使用 LocalAPI,可能会影响脚本的其他方面。经过验证的登录将更新为客户帐户存储的上次登录时间。成功后,将返回 userid 和 passwordhash。这可用于通过将会话 key ‘login_auth_tk’ 设置为 passwordhash 来建立经过身份验证的会话。
注意:如果启用了会话 IP 验证,则必须通过本地 API 执行此 API 调用才能接收有效的哈希。
注意:此 API 提供的登录函数被用于远程登录函数的 CreateSsoToken (https://developers.whmcs.com/api-reference/createssotoken/) 和用于身份验证服务/凭证验证的 OpenID Connect (https://docs.whmcs.com/OpenID_Connect) 取代。鉴于这些更强大和现代的实现,此 API 可能在未来被弃用。
请求参数
| 参数 | 类型 | 说明 | 必需的 |
|---|---|---|---|
| action | string | “ValidateLogin” | Required |
| string | 用户电子邮件地址 | Required | |
| password2 | string | 验证密码 | Required |
响应参数
| 参数 | 类型 | 说明 |
|---|---|---|
| result | string | 操作结果:成功或错误 |
| userid | int | 用户身份 |
| passwordhash | string | 登录会话令牌 - 如果帐户不需要 Two-Factor 身份验证,则返回 |
| twoFactorEnabled | bool | 如果为给定帐户启用了 Two-Factor 身份验证,则为真 |
示例请求 (CURL)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.example.com/includes/api.php');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
http_build_query(
array(
'action' => 'ValidateLogin',
// See https://developers.whmcs.com/api/authentication
'username' => 'IDENTIFIER_OR_ADMIN_USERNAME',
'password' => 'SECRET_OR_HASHED_PASSWORD',
'email' => '[email protected]',
'password2' => 'abc123',
'responsetype' => 'json',
)
)
);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
curl_close($ch);
示例请求(本地 API)
$command = 'ValidateLogin';
$postData = array(
'email' => '[email protected]',
'password2' => 'abc123',
);
$adminUsername = 'ADMIN_USERNAME'; // Optional for WHMCS 7.2 and later
$results = localAPI($command, $postData, $adminUsername);
print_r($results);
示例响应 JSON
{
"result": "success",
"userid": "1",
"passwordhash": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"twoFactorEnabled": "false"
}
错误响应
可能的错误条件响应包括:
- 电子邮件或密码无效
相关用法
- PHP WHMCS ViewOrderDetailsPage用法及代码示例
- PHP WHMCS ViewInvoiceDetailsPage用法及代码示例
- PHP WHMCS ClientAreaPageDownloads用法及代码示例
- PHP Ds\Map isEmpty()用法及代码示例
- PHP PHPUnit assertIsNotFloat()用法及代码示例
- PHP disk_total_space()用法及代码示例
- PHP ReflectionClass getTraitAliases()用法及代码示例
- PHP hash_hmac()用法及代码示例
- PHP String wordwrap()用法及代码示例
- PHP XMLWriter endPi()用法及代码示例
- PHP SimpleXMLElement children()用法及代码示例
- PHP IntlCalendar getTimeZone()用法及代码示例
- PHP SplPriorityQueue isCorrupted()用法及代码示例
- PHP XMLReader::getParserProperty()用法及代码示例
- PHP imagegif()用法及代码示例
- PHP imageresolution()用法及代码示例
- PHP array_reverse()用法及代码示例
- PHP IntlCalendar getActualMinimum()用法及代码示例
- PHP WHMCS DomainGetWhoisInfo用法及代码示例
- PHP metaphone()用法及代码示例
- PHP WHMCS ClientAreaHeaderOutput用法及代码示例
- PHP imagebmp()用法及代码示例
- PHP DOMDocument createElementNS()用法及代码示例
- PHP prev()用法及代码示例
- PHP Ds\Deque filter()用法及代码示例
注:本文由纯净天空筛选整理自whmcs.com大神的英文原创作品 ValidateLogin。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
