WinBioGetCredentialState 함수(winbio.h)
지정된 사용자에 대해 자격 증명이 설정되었는지 여부를 지정하는 값을 검색합니다. Windows 10 빌드 1607부터 이 함수를 모바일 이미지와 함께 사용할 수 있습니다.
구문
HRESULT WinBioGetCredentialState(
[in] WINBIO_IDENTITY Identity,
[in] WINBIO_CREDENTIAL_TYPE Type,
[out] WINBIO_CREDENTIAL_STATE *CredentialState
);
매개 변수
[in] Identity
자격 증명이 쿼리되는 사용자 계정의 SID를 포함하는 WINBIO_IDENTITY 구조체입니다.
[in] Type
자격 증명 형식을 지정하는 WINBIO_CREDENTIAL_TYPE 값입니다. 다음 값 중 하나일 수 있습니다.
값 | 의미 |
---|---|
|
암호 기반 자격 증명이 선택되어 있습니다. |
[out] CredentialState
사용자 자격 증명이 설정되었는지 여부를 지정하는 WINBIO_CREDENTIAL_STATE 열거형 값에 대한 포인터입니다. 다음 값 중 하나일 수 있습니다.
값 | 의미 |
---|---|
|
자격 증명을 지정하지 않았습니다. |
|
자격 증명이 지정되었습니다. |
반환 값
함수가 성공하면 S_OK를 반환합니다. 함수가 실패하면 오류를 나타내는 HRESULT 값을 반환합니다. 가능한 값에는 다음 표에 있는 값이 포함되지만, 이에 국한되는 것은 아닙니다. 일반적인 오류 코드 목록은 일반적인 HRESULT 값을 참조하세요.
반환 코드 | 설명 |
---|---|
|
호출자에게 자격 증명 상태를 검색할 수 있는 권한이 없습니다. |
|
지정된 ID가 없습니다. |
|
현재 관리 정책은 자격 증명 공급자의 사용을 금지합니다. |
설명
WinBioGetCredentialState는 일반적으로 사용자 인터페이스의 자격 증명 상태에 대한 피드백을 제공하는 데 사용됩니다. 예를 들어 등록 애플리케이션은 사용자에게 자격 증명을 요청하기 전에 자격 증명 상태를 쿼리할 수 있습니다.
WinBioSetCredential 함수를 호출하여 자격 증명을 사용자와 연결합니다.
상승된 권한이 없는 사용자는 자신의 자격 증명에 대한 정보만 검색할 수 있습니다. 관리자 권한 사용자는 모든 자격 증명에 대한 정보를 검색할 수 있습니다.
예제
다음 함수는 WinBioGetCredentialState 를 호출하여 사용자의 자격 증명 상태를 검색합니다. Winbio.lib 정적 라이브러리에 연결하고 다음 헤더 파일을 포함합니다.
- 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;
}
요구 사항
요구 사항 | 값 |
---|---|
지원되는 최소 클라이언트 | Windows 7 [데스크톱 앱만 해당] |
지원되는 최소 서버 | Windows Server 2008 R2 [데스크톱 앱만 해당] |
대상 플랫폼 | Windows |
헤더 | winbio.h(Winbio.h 포함) |
라이브러리 | Winbio.lib |
DLL | Winbio.dll |