Função WinBioGetCredentialState (winbio.h)

Recupera um valor que especifica se as credenciais foram definidas para o usuário especificado. A partir do Windows 10, build 1607, essa função está disponível para uso com uma imagem móvel.

Sintaxe

HRESULT WinBioGetCredentialState(
  [in]  WINBIO_IDENTITY         Identity,
  [in]  WINBIO_CREDENTIAL_TYPE  Type,
  [out] WINBIO_CREDENTIAL_STATE *CredentialState
);

Parâmetros

[in] Identity

Uma estrutura WINBIO_IDENTITY que contém o SID da conta de usuário para a qual a credencial está sendo consultada.

[in] Type

Um valor WINBIO_CREDENTIAL_TYPE que especifica o tipo de credencial. Esse valor pode ser um dos seguintes:

Valor Significado
WINBIO_CREDENTIAL_PASSWORD
A credencial baseada em senha é verificada.

[out] CredentialState

Ponteiro para um valor de enumeração WINBIO_CREDENTIAL_STATE que especifica se as credenciais do usuário foram definidas. Esse valor pode ser um dos seguintes:

Valor Significado
WINBIO_CREDENTIAL_NOT_SET
Uma credencial não foi especificada.
WINBIO_CREDENTIAL_SET
Uma credencial foi especificada.

Retornar valor

Se a função for bem-sucedida, ela retornará S_OK. Se a função falhar, ela retornará um valor HRESULT que indica o erro. Os possíveis valores incluem, mas sem limitação, aqueles na tabela a seguir. Para obter uma lista de códigos de erro comuns, consulte Valores HRESULT comuns.

Código de retorno Descrição
E_ACCESSDENIED
O chamador não tem permissão para recuperar o estado da credencial.
WINBIO_E_UNKNOWN_ID
A identidade especificada não existe.
WINBIO_E_CRED_PROV_DISABLED
A política administrativa atual proíbe o uso do provedor de credenciais.

Comentários

O WinBioGetCredentialState normalmente é usado para fornecer comentários sobre o estado da credencial em uma interface do usuário. Por exemplo, um aplicativo de registro pode consultar o estado da credencial antes de solicitar credenciais a um usuário.

Chame a função WinBioSetCredential para associar credenciais a um usuário.

Os usuários que não têm privilégios elevados podem recuperar informações apenas sobre suas próprias credenciais. Usuários elevados podem recuperar informações para qualquer credencial.

Exemplos

A função a seguir chama WinBioGetCredentialState para recuperar o estado de credencial de um usuário. Link para a biblioteca estática Winbio.lib e inclua os seguintes arquivos de cabeçalho:

  • Windows.h
  • Stdio.h
  • Conio.h
  • Winbio.h
HRESULT GetCredentialState()
{
    // Declare variables.
    HRESULT hr = S_OK;
    WINBIO_IDENTITY identity;
    WINBIO_CREDENTIAL_STATE credState;

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

    // Find the credential state for the user.
    wprintf_s(L"\n Calling WinBioGetCredentialState.\n");
    hr = WinBioGetCredentialState(
             identity,                      // User GUID or SID
             WINBIO_CREDENTIAL_PASSWORD,    // Credential type
             &credState                     // [out] Credential state
             );
    if (FAILED(hr))
    {
        wprintf_s(L"\n WinBioGetCredentialState failed. hr = 0x%x\n", hr);
        goto e_Exit;
    }

    // Print the credential state.
    switch(credState)
    {
        case WINBIO_CREDENTIAL_SET:
            wprintf_s(L"\n Credential set.\n");
            break;
        case WINBIO_CREDENTIAL_NOT_SET:
            wprintf_s(L"\n Credential NOT set.\n");
            break;
        default:
            wprintf_s(L"\n ERROR: Invalid credential state.\n");
            hr = E_FAIL;
    }

e_Exit:

    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;
}


Requisitos

Requisito Valor
Cliente mínimo com suporte Windows 7 [somente aplicativos da área de trabalho]
Servidor mínimo com suporte Windows Server 2008 R2 [somente aplicativos da área de trabalho]
Plataforma de Destino Windows
Cabeçalho winbio.h (inclua Winbio.h)
Biblioteca Winbio.lib
DLL Winbio.dll

Confira também

WinBioSetCredential