若要取得 認證, 與目前登入 會話相關聯的認證,請使用替代 安全性主體的資訊填入 SEC_WINNT_AUTH_IDENTITY 結構。 使用 pAuthData 參數,將結構體傳遞到 AcquireCredentialsHandle 函數。
下表描述 SEC_WINNT_AUTH_IDENTITY 結構的成員。
成員 | 描述 |
---|---|
使用者 | 以 Null 結尾的字串,包含將被用來建立安全性內容之安全性主體的名稱及其憑證。 |
UserLength | 使用者 成員的長度,以字元為單位。 省略終止空值。 |
網域 | 以 Null 結尾的字串,可識別包含安全性主體帳戶的網域。 |
DomainLength | 網域 成員的長度,以字元為單位。 省略終止符號null。 |
密碼 | 包含安全性主體密碼的以空字元結束的字串。 |
PasswordLength | 密碼 成員的長度,以字元為單位。 省略結尾的空值。 |
旗標 | 指出字串成員是否為 ANSI 或 Unicode 格式。 |
下表列出 旗標 結構成員的有效值。
恆定的 | 描述 |
---|---|
SEC_WINNT_AUTH_IDENTITY_ANSI | 此結構中的字串格式為 ANSI 格式。 |
SEC_WINNT_AUTH_IDENTITY_UNICODE | 此結構中的字串 Unicode 格式。 |
結構體和常數會在隨平台軟體開發套件(SDK)一起發行的 Rpcdce.h 標頭檔中宣告。
下列範例示範用戶端呼叫,以取得特定用戶帳戶的摘要認證。
#include <windows.h>
#ifdef UNICODE
ClientAuthID.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;
#else
ClientAuthID.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
#endif
void main()
{
SECURITY_STATUS SecStatus;
TimeStamp tsLifetime;
CredHandle hCred;
SEC_WINNT_AUTH_IDENTITY ClientAuthID;
LPTSTR UserName = TEXT("ASecurityPrinciple");
LPTSTR DomainName = TEXT("AnAuthenticatingDomain");
// Initialize the memory.
ZeroMemory( &ClientAuthID, sizeof(ClientAuthID) );
// Specify string format for the ClientAuthID structure.
// Specify an alternate user, domain and password.
ClientAuthID.User = (unsigned char *) UserName;
ClientAuthID.UserLength = _tcslen(UserName);
ClientAuthID.Domain = (unsigned char *) DomainName;
ClientAuthID.DomainLength = _tcslen(DomainName);
// Password is an application-defined LPTSTR variable
// containing the user password.
ClientAuthID.Password = Password;
ClientAuthID.PasswordLength = _tcslen(Password);
// Get the client side credential handle.
SecStatus = AcquireCredentialsHandle (
NULL, // Default principal.
WDIGEST_SP_NAME, // The Digest SSP.
SECPKG_CRED_OUTBOUND, // Client will use the credentials.
NULL, // Do not specify LOGON id.
&ClientAuthID, // User information.
NULL, // Not used with Digest SSP.
NULL, // Not used with Digest SSP.
&hCred, // Receives the credential handle.
&tsLifetime // Receives the credential time limit.
);
}
_tcslen 函式會傳回字元的字串長度,不包括終止的 Null 字元。
如果應用程式可以使用在登入時建立的認證,請參閱 取得預設摘要認證。