WinBioVerify 函式 (winbio.h)

擷取生物特徵辨識樣本,並判斷樣本是否對應至指定的使用者身分識別。 從 Windows 10 組建 1607 開始,此函式可用來搭配行動映射使用。

語法

HRESULT WinBioVerify(
  [in]            WINBIO_SESSION_HANDLE    SessionHandle,
  [in]            WINBIO_IDENTITY          *Identity,
  [in]            WINBIO_BIOMETRIC_SUBTYPE SubFactor,
  [out, optional] WINBIO_UNIT_ID           *UnitId,
  [out, optional] BOOLEAN                  *Match,
  [out, optional] WINBIO_REJECT_DETAIL     *RejectDetail
);

參數

[in] SessionHandle

識別開放式生物特徵辨識會話 的WINBIO_SESSION_HANDLE 值。 呼叫 WinBioOpenSession來開啟同步會話控制碼。 呼叫 WinBioAsyncOpenSession來開啟非同步會話控制碼。

[in] Identity

WINBIO_IDENTITY結構的指標,其中包含提供生物特徵辨識樣本之使用者的 GUID 或 SID。

[in] SubFactor

WINBIO_BIOMETRIC_SUBTYPE值,指定與生物特徵辨識樣本相關聯的子因素。 Windows 生物特徵辨識架構 (WBF) 目前僅支援指紋擷取,而且可以使用下列常數來表示子類型資訊。

  • WINBIO_ANSI_381_POS_RH_THUMB
  • WINBIO_ANSI_381_POS_RH_INDEX_FINGER
  • WINBIO_ANSI_381_POS_RH_MIDDLE_FINGER
  • WINBIO_ANSI_381_POS_RH_RING_FINGER
  • WINBIO_ANSI_381_POS_RH_LITTLE_FINGER
  • WINBIO_ANSI_381_POS_LH_THUMB
  • WINBIO_ANSI_381_POS_LH_INDEX_FINGER
  • WINBIO_ANSI_381_POS_LH_MIDDLE_FINGER
  • WINBIO_ANSI_381_POS_LH_RING_FINGER
  • WINBIO_ANSI_381_POS_LH_LITTLE_FINGER
  • WINBIO_ANSI_381_POS_RH_FOUR_FINGERS
  • WINBIO_ANSI_381_POS_LH_FOUR_FINGERS
  • WINBIO_SUBTYPE_ANY

[out, optional] UnitId

指定執行驗證之生物特徵辨識單位 之WINBIO_UNIT_ID 值的指標。

[out, optional] Match

布林值的指標,指定擷取的樣本是否符合 Identity 參數所指定的使用者身分識別。

[out, optional] RejectDetail

ULONG值的指標,其中包含擷取生物特徵辨識樣本失敗的其他資訊。 如果擷取成功,此參數會設定為零。 針對指紋擷取定義了下列值:

  • WINBIO_FP_TOO_HIGH
  • WINBIO_FP_TOO_LOW
  • WINBIO_FP_TOO_LEFT
  • WINBIO_FP_TOO_RIGHT
  • WINBIO_FP_TOO_FAST
  • WINBIO_FP_TOO_SLOW
  • WINBIO_FP_POOR_QUALITY
  • WINBIO_FP_TOO_SKEWED
  • WINBIO_FP_TOO_SHORT
  • WINBIO_FP_MERGE_FAILURE

傳回值

如果函式成功,它會傳回S_OK。 如果函式失敗,它會傳回 HRESULT 值,指出錯誤。 可能的值包括 (但不限於) 下表中的這些值。 如需常見錯誤碼的清單,請參閱 一般 HRESULT 值

傳回碼 描述
E_HANDLE
會話控制碼無效。
E_INVALIDARG
SubFactor引數不正確。
E_POINTER
UnitIdIdentitySubFactorRejectDetail參數指定的指標不能是Null
WINBIO_E_BAD_CAPTURE
無法擷取生物特徵辨識樣本。 如需詳細資訊,請使用 RejectDetail 值。
WINBIO_E_ENROLLMENT_IN_PROGRESS
作業無法完成,因為指定的生物特徵辨識單位目前正在用於註冊交易 (系統集區) 。
WINBIO_E_NO_MATCH
生物特徵辨識樣本不會對應至指定的 IdentitySubFactor 組合。

備註

如果生物特徵辨識樣本的擷取失敗, UnitId 參數會包含嘗試執行擷取之感應器的單位編號。

使用系統集區的呼叫將會封鎖,直到應用程式取得視窗焦點,且使用者已提供生物特徵辨識範例為止。 因此,建議您在應用程式取得焦點之前,不要呼叫 WinBioVerify 。 取得焦點的方式取決於您正在撰寫的應用程式類型。 例如,如果您要建立 GUI 應用程式,您可以實作擷取WM_ACTI加值稅E、WM_SETFOCUS或其他適當訊息的訊息處理常式。 如果您要撰寫 CUI 應用程式,請呼叫 GetConsoleWindow 以擷取主控台視窗的控制碼,並將該控制碼傳遞給 SetForegroundWindow 函式,以強制主控台視窗進入前景並指派焦點。 如果您的應用程式是在中斷連結的進程中執行,而且沒有視窗或是 Windows 服務,請使用 WinBioAcquireFocusWinBioReleaseFocus 手動控制焦點。

若要以同步方式使用 WinBioVerify ,請使用呼叫 WinBioOpenSession所建立的會話控制碼呼叫函式。 函式會封鎖直到作業完成或發生錯誤為止。

若要以非同步方式使用 WinBioVerify ,請使用呼叫 WinBioAsyncOpenSession所建立的會話控制碼呼叫函式。 架構會配置 WINBIO_ASYNC_RESULT 結構,並用它來傳回作業成功或失敗的相關資訊。 如果作業成功,架構會在巢狀驗證結構中傳回BOOLEAN比對值。 如果作業失敗,架構會傳回[驗證] 結構中的WINBIO_REJECT_DETAIL資訊。 WINBIO_ASYNC_RESULT結構會根據您在WinBioAsyncOpenSession函式的NotificationMethod參數中設定的值,傳回至應用程式回呼或應用程式訊息佇列:

  • 如果您選擇使用回呼接收完成通知,則必須實作 PWINBIO_ASYNC_COMPLETION_CALLBACK 函式,並將 NotificationMethod 參數設定為 WINBIO_ASYNC_NOTIFY_CALLBACK
  • 如果您選擇使用應用程式訊息佇列接收完成通知,您必須將 NotificationMethod 參數設定為 WINBIO_ASYNC_NOTIFY_MESSAGE。 架構會傳回視窗訊息之LPARAM欄位的WINBIO_ASYNC_RESULT指標。
若要防止記憶體流失,您必須呼叫 WinBioFree ,以在您使用完 之後釋放WINBIO_ASYNC_RESULT 結構。

Windows 7: 您可以使用 WinBioVerifyWithCallback 函式,以非同步方式執行這項作業。 函式會驗證輸入引數,並立即傳回 。 如果輸入引數無效,函式會傳回錯誤碼。 否則,架構會在另一個執行緒上啟動作業。 當非同步作業完成或發生錯誤時,架構會將結果傳送至應用程式所實作 的PWINBIO_VERIFY_CALLBACK 函式。

範例

下列函式會呼叫 WinBioVerify ,以判斷生物特徵辨識樣本是否符合目前使用者的登入身分識別。 也包含協助程式函式 GetCurrentUserIdentity。 連結到 Winbio.lib 靜態程式庫,並包含下列標頭檔:

  • Windows.h
  • Stdio.h
  • Conio.h
  • Winbio.h
HRESULT Verify(WINBIO_BIOMETRIC_SUBTYPE subFactor)
{
    HRESULT hr = S_OK;
    WINBIO_SESSION_HANDLE sessionHandle = NULL;
    WINBIO_UNIT_ID unitId = 0;
    WINBIO_REJECT_DETAIL rejectDetail = 0;
    WINBIO_IDENTITY identity = {0};
    BOOLEAN match = FALSE;

    // Find the identity of the user.
    hr = GetCurrentUserIdentity( &identity );
    if (FAILED(hr))
    {
        wprintf_s(L"\n User identity not found. hr = 0x%x\n", hr);
        goto e_Exit;
    }

    // Connect to the system pool. 
    hr = WinBioOpenSession( 
            WINBIO_TYPE_FINGERPRINT,    // Service provider
            WINBIO_POOL_SYSTEM,         // Pool type
            WINBIO_FLAG_DEFAULT,        // Configuration and access
            NULL,                       // Array of biometric unit IDs
            0,                          // Count of biometric unit IDs
            NULL,                       // Database ID
            &sessionHandle              // [out] Session handle
            );
    if (FAILED(hr))
    {
        wprintf_s(L"\n WinBioOpenSession failed. hr = 0x%x\n", hr);
        goto e_Exit;
    }

    // Verify a biometric sample.
    wprintf_s(L"\n Calling WinBioVerify - Swipe finger on sensor...\n");
    hr = WinBioVerify( 
            sessionHandle, 
            &identity, 
            subFactor, 
            &unitId, 
            &match,
            &rejectDetail
            );
    wprintf_s(L"\n Swipe processed - Unit ID: %d\n", unitId);
    if (FAILED(hr))
    {
        if (hr == WINBIO_E_NO_MATCH)
        {
            wprintf_s(L"\n- NO MATCH - identity verification failed.\n");
        }
        else if (hr == WINBIO_E_BAD_CAPTURE)
        {
            wprintf_s(L"\n- Bad capture; reason: %d\n", rejectDetail);
        }
        else
        {
        wprintf_s(L"\n WinBioVerify failed. hr = 0x%x\n", hr);
        }
        goto e_Exit;
    }
    wprintf_s(L"\n Fingerprint verified:\n", unitId);


e_Exit:
    if (sessionHandle != NULL)
    {
        WinBioCloseSession(sessionHandle);
        sessionHandle = NULL;
    }

    wprintf_s(L"\n Press any key to exit...");
    _getch();

    return hr;
}

//------------------------------------------------------------------------
// The following function retrieves the identity of the current user.
// This is a helper function and is not part of the Windows Biometric
// Framework API.
//
HRESULT GetCurrentUserIdentity(__inout PWINBIO_IDENTITY Identity)
{
    // Declare variables.
    HRESULT hr = S_OK;
    HANDLE tokenHandle = NULL;
    DWORD bytesReturned = 0;
    struct{
        TOKEN_USER tokenUser;
        BYTE buffer[SECURITY_MAX_SID_SIZE];
    } tokenInfoBuffer;

    // Zero the input identity and specify the type.
    ZeroMemory( Identity, sizeof(WINBIO_IDENTITY));
    Identity->Type = WINBIO_ID_TYPE_NULL;

    // Open the access token associated with the
    // current process
    if (!OpenProcessToken(
            GetCurrentProcess(),            // Process handle
            TOKEN_READ,                     // Read access only
            &tokenHandle))                  // Access token handle
    {
        DWORD win32Status = GetLastError();
        wprintf_s(L"Cannot open token handle: %d\n", win32Status);
        hr = HRESULT_FROM_WIN32(win32Status);
        goto e_Exit;
    }

    // Zero the tokenInfoBuffer structure.
    ZeroMemory(&tokenInfoBuffer, sizeof(tokenInfoBuffer));

    // Retrieve information about the access token. In this case,
    // retrieve a SID.
    if (!GetTokenInformation(
            tokenHandle,                    // Access token handle
            TokenUser,                      // User for the token
            &tokenInfoBuffer.tokenUser,     // Buffer to fill
            sizeof(tokenInfoBuffer),        // Size of the buffer
            &bytesReturned))                // Size needed
    {
        DWORD win32Status = GetLastError();
        wprintf_s(L"Cannot query token information: %d\n", win32Status);
        hr = HRESULT_FROM_WIN32(win32Status);
        goto e_Exit;
    }

    // Copy the SID from the tokenInfoBuffer structure to the
    // WINBIO_IDENTITY structure. 
    CopySid(
        SECURITY_MAX_SID_SIZE,
        Identity->Value.AccountSid.Data,
        tokenInfoBuffer.tokenUser.User.Sid
        );

    // Specify the size of the SID and assign WINBIO_ID_TYPE_SID
    // to the type member of the WINBIO_IDENTITY structure.
    Identity->Value.AccountSid.Size = GetLengthSid(tokenInfoBuffer.tokenUser.User.Sid);
    Identity->Type = WINBIO_ID_TYPE_SID;

e_Exit:

    if (tokenHandle != NULL)
    {
        CloseHandle(tokenHandle);
    }

    return hr;
}


規格需求

   
最低支援的用戶端 Windows 7 [僅限傳統型應用程式]
最低支援的伺服器 Windows Server 2008 R2 [僅限傳統型應用程式]
目標平台 Windows
標頭 winbio.h (包含 Winbio.h)
程式庫 Winbio.lib
Dll Winbio.dll

另請參閱

WinBioVerifyWithCallback