共用方式為


取得替代摘要認證

若要取得與目前登入會話相關聯的認證,請使用替代安全性主體的資訊填入SEC_WINNT_AUTH_IDENTITY結構。 使用pAuthData參數將 結構傳遞至AcquireCredentialsHandle函式。

下表描述 SEC_WINNT_AUTH_IDENTITY 結構的成員。

member Description
使用者 以 Null 結尾的字串,其中包含其認證將用來建立安全性內容的安全性主體名稱。
UserLength User成員的長度,以字元為單位。 省略終止 Null。
網域 以 Null 終止的字串,識別包含安全性主體帳戶的網域。
DomainLength 網域成員的長度,以字元為單位。 省略終止 Null。
密碼 包含安全性主體密碼的 Null 終止字串。
PasswordLength Password成員的長度,以字元為單位。 省略終止 Null。
旗標 指出字串成員是否為 ANSI 或 Unicode 格式。

 

下表列出 結構 之 Flags 成員的有效值。

常數 描述
SEC_WINNT_AUTH_IDENTITY_ANSI 此結構中的字串格式為 ANSI 格式。
SEC_WINNT_AUTH_IDENTITY_UNICODE 此結構中的字串格式為 Unicode 格式。

 

結構和常數會在以 Platform Software Development Kit (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 字元。

如果您的應用程式可以使用在登入時建立的認證,請參閱 取得預設摘要認證