Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works
Anything · Lazarus or Delphi
Random projectRandom project

UserConsent

Windows Hello (fingerprint / face / PIN) user verification for Delphi VCL — a tiny SCUserConsent wrapper

View on GitHub

Member rating

No ratings yet.

Sign in to rate this project.

README

Windows Hello 인증 (SCUserConsent)

English · 한국어

델파이에서 Windows Hello(지문·얼굴·PIN)로 사용자 신원을 확인하는 방법과, 이를 감싼 SCUserConsent 유닛의 사용법을 설명합니다. 비밀번호 입력이나 로그인을 생체 인증으로 대체할 때 사용합니다.

Windows Hello 란

Windows Hello 는 Windows 10 이상에 내장된 인증 프레임워크로, 비밀번호 없이 다음 수단으로 사용자를 확인합니다.

  • 지문(지문 센서)
  • 얼굴 인식(적외선 카메라)
  • PIN(장치에 귀속된 PIN)

앱은 자격 증명 자체를 다루지 않습니다. OS 가 안전한 시스템 UI(별도 보안 표면)에서 사용자를 확인하고, 앱에는 성공/실패 결과만 돌려줍니다. 즉 지문·얼굴 데이터가 앱으로 넘어오지 않으므로 안전합니다.

내부적으로는 WinRT API Windows.Security.Credentials.UI.UserConsentVerifier 를 사용합니다.

지원 환경

항목 요구 사항
운영체제 Windows 10 이상 (Windows Hello 지원 및 PIN/지문/얼굴 등록 필요)
델파이 WinRT 바인딩(Winapi.Security.Credentials)을 포함한 모던 델파이. 본 유닛은 Delphi 13 (RAD Studio 37.0) 에서 검증됨.
플랫폼 Win32 / Win64 모두 지원
패키징 MSIX 패키지 아이덴티티 불필요 — 일반 Win32 데스크톱 앱에서 그대로 동작

미지원 환경(구형 Windows, Hello 미설정 등)에서는 예외를 던지지 않고 NotSupported / NotConfigured 등의 상태로 안전하게 반환합니다.

데스크톱 앱에서의 핵심 (HWND 연결)

순수 WinRT UserConsentVerifier.RequestVerificationAsync 는 UWP 용으로 설계되어, 클래식 Win32 앱에서는 동의 다이얼로그가 창에 연결되지 않아 제대로 표시되지 않을 수 있습니다.

SCUserConsent 는 델파이 RTL 이 제공하지 않는 IUserConsentVerifierInterop(IID {39E050C3-4E74-441A-8DC0-B81104DF949C})를 직접 선언해, 폼의 HWND 를 다이얼로그에 연결합니다. 따라서 일반 VCL 데스크톱 앱에서도 정상적으로 동작합니다. WinRT 비동기 호출은 STA 메시지 펌프로 동기 대기하므로, Verify 는 다이얼로그가 닫힐 때까지 기다렸다가 결과를 반환합니다.

사용법

uses 에 SCUserConsent 만 추가하면 됩니다(다른 의존성 없음).

pascal
uses
  SCUserConsent;

// 1) Windows Hello 를 쓸 수 있는지 확인
if TSCUserConsent.IsAvailable then
begin
  // 2) 인증 요청 — 다이얼로그가 끝날 때까지 대기(동기)
  //    두 번째 인자는 다이얼로그를 연결할 창 핸들. 0 이면 현재 활성 창.
  if TSCUserConsent.Verify('로그인하려면 인증하세요.', Handle).IsVerified then
  begin
    // 인증 성공 → 로그인/보호된 작업 진행
    ShowMessage('환영합니다!');
  end
  else
  begin
    ShowMessage('인증에 실패했거나 취소되었습니다.');
  end;
end
else
begin
  // 지문/PIN 미설정 등 — 비밀번호 등 대체 수단으로 폴백
  ShowMessage('이 PC 에서는 Windows Hello 를 사용할 수 없습니다.');
end;

API 요약

pascal
type
  TSCUserConsent = class
    class function CheckAvailability: TSCUserConsentAvailability;
    class function IsAvailable: Boolean;   // CheckAvailability = ucaAvailable 단축
    class function Verify(const AMessage: string; AWindow: HWND = 0): TSCUserConsentResult;
  end;

TSCUserConsentAvailability — 사용 가능 여부

값 의미
ucaAvailable 사용 가능(Hello 설정됨)
ucaDeviceNotPresent 생체 장치 없음
ucaNotConfigured Windows Hello 미설정(등록 필요)
ucaDisabledByPolicy 정책으로 비활성
ucaDeviceBusy 장치 사용 중
ucaNotSupported 지원되지 않음(구형 OS 등)

TSCUserConsentResult — 검증 결과

값 의미
ucrVerified 인증 성공
ucrDeviceNotPresent 생체 장치 없음
ucrNotConfigured Hello 미설정
ucrDisabledByPolicy 정책으로 비활성
ucrDeviceBusy 장치 사용 중
ucrRetriesExhausted 재시도 횟수 초과
ucrCanceled 사용자가 취소
ucrNotSupported 지원되지 않음
ucrError 기타 오류

두 열거형에는 ToString(소문자 문자열)과 IsAvailable / IsVerified 헬퍼가 있습니다.

pascal
var LRes := TSCUserConsent.Verify('인증하세요', Handle);
if LRes.IsVerified then ... ;
Log('결과: ' + LRes.ToString);   // 예: 'verified', 'canceled'

데모

src\UserConsentDemo.dpr 를 빌드해 실행하면(bin\UserConsentDemo.exe):

  • 가용성 확인 버튼 — 현재 PC 의 Windows Hello 상태 표시
  • 지문 · PIN 으로 인증 버튼 — Hello 다이얼로그를 띄워 인증(성공=녹색, 실패/취소=적색)

Windows Hello 가 설정된 PC 에서 실제 지문/PIN 검증을 확인할 수 있습니다. 미설정 PC 에서는 "미설정" 상태와 함께 인증 버튼이 비활성으로 표시됩니다.

명령줄 빌드

pascal
dcc64 -B src\UserConsentDemo.dpr -NSWinapi;System;System.Win;Vcl -Usrc -Ebin

프로젝트 구성

pascal
UserConsent\
  src\    SCUserConsent.pas          # ?????? ??????(????????? ?????????)
          UserConsentDemo.dpr        # ?????? ????????????
          UserConsent.Main.pas/.dfm  # ?????? ???(?????? VCL)
  bin\    UserConsentDemo.exe        # ?????? ?????????
  README.md / README.en.md          # ??????(????????? / English)

라이선스

MIT License.