共用方式為


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 開啟同步會話的 handle 。 透過呼叫 WinBioAsyncOpenSession 開啟非同步會話句柄。

[in] Identity

指標指向包含提供生物特徵樣本使用者 GUID 或 SID 的 WINBIO_IDENTITY 結構。

[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 值

回傳碼 Description
E_HANDLE
工作階段控制碼無效。
E_INVALIDARG
因子 的論點是錯誤的。
E_POINTER
UnitIdIdentitySubFactorRejectDetail 參數指定的指標不能是 NULL。
WINBIO_E_BAD_CAPTURE
無法捕捉到生物特徵樣本。 請使用 RejectDetail 值以獲得更多資訊。
WINBIO_E_ENROLLMENT_IN_PROGRESS
由於指定的生物特徵單位目前正用於註冊交易(僅限系統池),該操作無法完成。
WINBIO_E_NO_MATCH
生物特徵樣本不符合指定的 身份子因子 組合。

備註

若生物特徵樣本擷取失敗, UnitId 參數將包含嘗試擷取的感測器單位編號。

使用系統池呼叫此功能會阻塞,直到應用程式取得視窗焦點且使用者提供生物特徵樣本。 因此,我們建議您的應用程式在獲得焦點之前,不要呼叫 WinBioVerify 。 你如何獲得專注,取決於你所撰寫的申請類型。 舉例來說,如果你正在建立一個圖形使用者體驗應用程式,你可以實作一個訊息處理器來捕捉WM_ACTIVATE、WM_SETFOCUS或其他適當的訊息。 如果你正在撰寫 CUI 應用程式,呼叫 GetConsoleWindow 取得主控台視窗的 handle,並將該 handle 傳給 SetForegroundWindow 函式,強制將主控台視窗移到前景並指派焦點。 如果你的應用程式是在分離程序中執行且沒有視窗,或是 Windows 服務,請使用 WinBioAcquireFocusWinBioReleaseFocus 手動控制焦點。

若要同步使用 WinBioVerify ,請呼叫由 WinBioOpenSession 建立的會話句柄。 該函式會阻塞,直到操作完成或遇到錯誤。

若要非同步使用 WinBioVerify ,請呼叫該函式,並以呼叫 WinBioAsyncOpenSession 建立的會話句柄。 該框架分配一個 WINBIO_ASYNC_RESULT 結構,並用它來回傳有關操作成功或失敗的資訊。 若操作成功,框架會以巢狀 Verify 結構回傳一個布林匹配值。 若操作失敗,框架會在 Verify 結構中回傳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
  • 標準.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;
}


需求

Requirement 價值觀
最低支援的用戶端 Windows 7 [僅限桌面應用程式]
支援的最低伺服器 Windows Server 2008 R2 [僅限傳統型應用程式]
目標平臺 窗戶
Header winbio.h(包括Winbio.h)
Library Winbio.lib 網站
DLL Winbio.dll

另請參閱

WinBioVerifyWithCallback