1 回答
TA贡献1817条经验 获得超14个赞
C 或 C++ 中的解决方案也会很有用
这是使用CoreServices的 C 语言示例。为简洁起见,省略了错误和结果检查:
void on_logon(const char* username, const char* password) {
CSIdentityQueryRef query;
CFArrayRef idArray = NULL;
CSIdentityRef result;
CFStringRef cfUsername = NULL;
CFStringRef cfPassword = NULL;
cfUsername = CFStringCreateWithCString(NULL, username, kCFStringEncodingUTF8);
query = CSIdentityQueryCreateForName(kCFAllocatorDefault, cfUsername, kCSIdentityQueryStringEquals, kCSIdentityClassUser, CSGetDefaultIdentityAuthority());
CSIdentityQueryExecute(query, kCSIdentityQueryGenerateUpdateEvents, NULL);
idArray = CSIdentityQueryCopyResults(query);
if (CFArrayGetCount(idArray) != 1)
{
// Username didn't match...
}
result = (CSIdentityRef) CFArrayGetValueAtIndex(idArray, 0);
cfPassword = CFStringCreateWithCString(NULL, password, kCFStringEncodingUTF8);
if (CSIdentityAuthenticateUsingPassword(result, cfPassword))
{
// Username and password are valid!!
}
CFRelease(cfUsername);
CFRelease(idArray);
CFRelease(cfPassword);
CFRelease(query);
}
- 1 回答
- 0 关注
- 108 浏览
添加回答
举报