Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
        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);
            });
        }
Ejemplo n.º 3
0
        public EnrollViewModel()
        {
            BiometricSubtypeNames =
                new Dictionary <BiometricSubtype, string>
            {
                { BiometricSubtype.LeftIndexFinger, "Left Index Finger" },
                { BiometricSubtype.LeftMiddleFinger, "Left Middle Finger" },
                { BiometricSubtype.LeftRingFinger, "Left Ring Finger" },
                { BiometricSubtype.LeftLittleFinger, "Left Little Finger" },
                { BiometricSubtype.LeftThumb, "Left Thumb" },
                { BiometricSubtype.RightIndexFinger, "Right Index Finger" },
                { BiometricSubtype.RightMiddleFinger, "Right Middle Finger" },
                { BiometricSubtype.RightRingFinger, "Right Ring Finger" },
                { BiometricSubtype.RightLittleFinger, "Right Little Finger" },
                { BiometricSubtype.RightThumb, "Right Thumb" }
            };

            PropertyChanged += async(s, e) =>
            {
                if (e.PropertyName == "Finger" && Finger != BiometricSubtype.Any)
                {
                    await Task.Run(() =>
                    {
                        try
                        {
                            WBF.Enroll(WBF.GetCurrentIdentity(), Sensor, Finger, ep =>
                            {
                                switch (ep)
                                {
                                case EnrollPrompt.UseSensor:
                                    Message = "Please touch or swipe the sensor again.";
                                    break;

                                case EnrollPrompt.NeedMoreData:
                                    Message = "Please touch or swipe the sensor again, I need more data.";
                                    UI(() => FingerprintAccepted?.Invoke(this, null));
                                    break;

                                case EnrollPrompt.BadCapture:
                                    Message = "Please touch or swipe the sensor again, I didn't catch that.";
                                    UI(() => FingerprintRejected?.Invoke(this, null));
                                    break;

                                case EnrollPrompt.Success:
                                    Message = "Done!";
                                    UI(() => FingerprintCompleted?.Invoke(this, null));
                                    break;
                                }
                            });
                        }
                        catch (Exception ex)
                        {
                            Message = ex.Message;
                        }
                    });
                }
            };

            Task.Run(() =>
            {
                Message = "Swipe or touch the sensor that you wish to use.";
                Sensor  = WBF.LocateSensor();
                Finger  = BiometricSubtype.Any;

                var fingers           = WBF.GetEnrollments(WBF.GetCurrentIdentity(), Sensor);
                BiometricSubtypeNames =
                    (from kv in BiometricSubtypeNames
                     where !fingers.Contains(kv.Key)
                     select kv).ToDictionary(kv => kv.Key, kv => kv.Value);
                RaisePropertyChanged(nameof(BiometricSubtypeNames));
            });
        }