示例#1
0
        private static void Main(string[] args)
        {
            //try
            //{
            var schemas = WBF.GetBiometricUnits(BiometricType.Fingerprint);
            var session = WBF.OpenSession(BiometricType.Fingerprint, BiometricPoolType.System, BiometricSessionFlags.Default,
                                          null, BiometricDatabaseType.None);
            var identity = WBF.GetCurrentIdentity();

            while (!Console.KeyAvailable)
            {
                var match = WBF.Verify(session, identity, BiometricSubtype.Any,
                                       out uint schema, out BiometricRejectDetail rejectDetail, out BiometricError error);

                if (error == BiometricError.None)
                {
                    Console.WriteLine("Match: {0}", match);
                }
                else
                {
                    Console.WriteLine("Biometric Error: {0}", error);
                    Console.WriteLine("Reject detail: {0}", rejectDetail);
                }
            }

            WBF.CloseSession(session);
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine("Error: {0}", ex.Message);
            //}
            Console.ReadLine();
        }
        private async Task ValidateFingerprint()
        {
            BiometricsEnabled =
                BiometricsEnabled &&
                WBF.GetBiometricUnits(BiometricType.Fingerprint).Length > 0;

            if (!BiometricsEnabled)
            {
                return;
            }

            await Task.Run(() =>
            {
                var session =
                    WBF.OpenSession(BiometricType.Fingerprint, BiometricSessionFlags.Default,
                                    null, BiometricDatabaseType.None);

                var match = false;

                try
                {
                    while (!WBF.Verify(session, WBF.GetCurrentIdentity(), BiometricSubtype.Any,
                                       out uint unitId, out BiometricRejectDetail rejectDetail, out BiometricError error))
                    {
                        PasswordVerificationStatus = PasswordVerificationStatus.Rejected;
                        UI(() => BiometricRejected?.Invoke(this, null));

                        switch (error)
                        {
                        case BiometricError.None:
                            PasswordErrorMessage = "There was no error?";
                            break;

                        case BiometricError.BadCapture:
                            switch (rejectDetail)
                            {
                            case BiometricRejectDetail.TooHigh:
                                PasswordErrorMessage = "Your finger was too high.";
                                break;

                            case BiometricRejectDetail.TooLow:
                                PasswordErrorMessage = "Your finger was too low.";
                                break;

                            case BiometricRejectDetail.TooLeft:
                                PasswordErrorMessage = "Your finger was too far to the left.";
                                break;

                            case BiometricRejectDetail.TooRight:
                                PasswordErrorMessage = "Your finger was too far to the right.";
                                break;

                            case BiometricRejectDetail.TooFast:
                                PasswordErrorMessage = "You moved your finger too quickly.";
                                break;

                            case BiometricRejectDetail.TooSlow:
                                PasswordErrorMessage = "You moved your finger too slowly.";
                                break;

                            case BiometricRejectDetail.PoorQuality:
                                PasswordErrorMessage = "Your fingerprint could not be read properly.";
                                break;

                            case BiometricRejectDetail.TooSkewed:
                                PasswordErrorMessage = "The fingerprint capture was too skewed.";
                                break;

                            case BiometricRejectDetail.TooShort:
                                PasswordErrorMessage = "Your finger was too short.";
                                break;

                            case BiometricRejectDetail.MergeFailure:
                                PasswordErrorMessage = "Try again.";
                                break;

                            default:
                                break;
                            }
                            break;

                        case BiometricError.EnrollmentInProgress:
                            PasswordErrorMessage = "The sensor is currently enrolling a new fingerprint.";
                            break;

                        case BiometricError.NoMatch:
                            PasswordErrorMessage = "The fingerprint did not match.";
                            break;

                        default:
                            break;
                        }
                    }
                    match = true;
                }
                catch
                {
                }

                if (match)
                {
                    PasswordVerificationStatus = PasswordVerificationStatus.Verified;
                    UI(() => BiometricVerified?.Invoke(this, null));
                }

                WBF.CloseSession(session);
            });
        }