protected override void OnLoad(EventArgs e) { _identity = null; comboUnitId.Items.Clear(); comboUnitId.ResetText(); var units = WinBio.EnumBiometricUnits(WinBioBiometricType.Fingerprint); Log(string.Format("Found {0} units", units.Length)); if (units.Length == 0) { return; } for (int i = 0; i < units.Length; i++) { Log(string.Format("- Unit id: {0}", units[i].UnitId)); comboUnitId.Items.Add(units[i].UnitId); string strDeviceInstanceId = units[i].DeviceInstanceId; Log(string.Format(" Unit id: {0}", strDeviceInstanceId)); string strFirmwareVersion = getFirmwareVersion(strDeviceInstanceId); if (strFirmwareVersion.Equals("")) { Log(string.Format(" Firmware: {0}", units[i].FirmwareVersion.ToString())); } else { Log(string.Format(" Firmware: {0}", strFirmwareVersion)); } int lastInvSlash = units[i].DeviceInstanceId.LastIndexOf("\\"); Log(string.Format(" Key code: {0}", strDeviceInstanceId.Substring(lastInvSlash + 1, strDeviceInstanceId.Length - lastInvSlash - 1))); } _unitId = units[0].UnitId; setComboxSelectedIndex(comboUnitId, 0); // use 1st one by default. Log(string.Format("Using unit id: {0}", _unitId)); _session = WinBio.OpenSession(WinBioBiometricType.Fingerprint, WinBioPoolType.System, WinBioSessionFlag.Default, null, 0); Log("Session opened: " + _session.Value); comboBoxFp.Items.Clear(); comboBoxFp.ResetText(); String[] myArr = new String[] { "Unknown",//0 "RhThumb", "RhIndexFinger", "RhMiddleFinger", "RhRingFinger", "RhLittleFinger", "LhThumb", "LhIndexFinger", "LhMiddleFinger", "LhRingFinger", "LhLittleFinger" }; //10 comboBoxFp.Items.AddRange(myArr); setComboxSelectedIndex(comboBoxFp, 1); }
public void AquireFocus() { try { ReleaseFocus(); Debug("Aquiring focus..."); WinBioErrorCode result = WinBio.AcquireFocus(); Debug(result.ToString()); if (result == WinBioErrorCode.Ok) { UpdateStatus(Statuses.Listening); } else { throw new Exception("Non-OK response trying to aquire focus."); } } catch (Exception e) { Debug("Error aquiring focus"); Debug(e.Message); UpdateStatus(Statuses.NoFocus); } }
private void InitialStart() { // Stop Windows Biometric Service to apply changes RestartService("WbioSrvc", 5000, ServiceMode.Stop); var databases = WinBio.EnumDatabases(WinBioBiometricType.Fingerprint); Console.WriteLine("Found {0} databases", databases.Length); for (var i = 0; i < databases.Length; i++) { Console.WriteLine("DatabaseId {0}: {1}", i, databases[i].DatabaseId); } if (WinBioConfiguration.DatabaseExists(DatabaseId)) { Console.WriteLine("Removing database: {0}", DatabaseId); WinBioConfiguration.RemoveDatabase(DatabaseId); } // Start Windows Biometric Service to apply changes RestartService("WbioSrvc", 5000, ServiceMode.Start); Console.WriteLine("Creating database: {0}", DatabaseId); WinBioConfiguration.AddDatabase(DatabaseId, _unitId); Console.WriteLine("Adding sensor to the pool: {0}", _unitId); WinBioConfiguration.AddUnit(DatabaseId, _unitId); // Restart Windows Biometric Service to apply changes RestartService("WbioSrvc", 5000, ServiceMode.Restart); Log("Successfully recreated database."); OpenBiometricSession(); }
private WinBioIdentity AddEnrollment(WinBioSessionHandle session, int unitId, WinBioBiometricSubType subType) { Log(string.Format("Beginning enrollment of {0}:", subType)); WinBio.EnrollBegin(session, subType, unitId); var code = WinBioErrorCode.MoreData; for (var swipes = 1; code != WinBioErrorCode.Ok; swipes++) { WinBioRejectDetail rejectDetail; code = WinBio.EnrollCapture(session, out rejectDetail); switch (code) { case WinBioErrorCode.MoreData: Log(string.Format("Swipe {0} was good", swipes)); break; case WinBioErrorCode.BadCapture: Log(string.Format("Swipe {0} was bad: {1}", swipes, rejectDetail)); break; case WinBioErrorCode.Ok: Log(string.Format("Enrollment complete with {0} swipes", swipes)); break; default: throw new WinBioException(code, "WinBioEnrollCapture failed"); } } Log(string.Format("Committing enrollment..")); WinBioIdentity identity; var isNewTemplate = WinBio.EnrollCommit(session, out identity); Log(string.Format(isNewTemplate ? "New template committed." : "Template already existing.")); return(identity); }
/// <summary> /// Checks to see if there is an available fingerprint sensor /// If no devices are available, we set the status to NoDevice /// </summary> public void CheckDevices() { try { Debug("Searching for fingerprint sensors..."); var units = WinBio.EnumBiometricUnits(WinBioBiometricType.Fingerprint); Debug(string.Format("Found {0} sensors", units.Length)); // Check if we have a connected fingerprint sensor if (units.Length == 0) { throw new Exception("No units"); } else { UpdateStatus(Statuses.NoSession); } } catch (Exception e) { Debug("Could not find fingerprint sensor"); Debug(e.Message); UpdateStatus(Statuses.NoDevice); } }
/// <summary> /// Attempts to listen for a single fingerprint read. /// Returns true on a successful listen, or false if something went wrong /// </summary> public bool Listen() { Debug("Identifying user..."); try { WinBioIdentity identity; WinBioBiometricSubType subFactor; WinBioRejectDetail rejectDetail; WinBio.Identify(_session, out identity, out subFactor, out rejectDetail); Debug(string.Format("Identity: {0}", identity)); Debug(identity.TemplateGuid.ToString()); onIdentify(identity.AccountSid.ToString()); return(true); } catch (WinBioException ex) { if (ex.ErrorCode == WinBioErrorCode.UnknownID) { onUnknownIdentity(); return(true); } Debug(ex); } catch (Exception ex) { Debug(ex.Message); } return(false); }
protected override void OnLoad(EventArgs e) { var units = WinBio.EnumBiometricUnits(WinBioBiometricType.Fingerprint); Log(string.Format("Found {0} units", units.Length)); // Check if we have a connected fingerprint sensor if (units.Length == 0) { MessageBox.Show("Error: Fingerprint sensor not found! Exiting...", "Error", MessageBoxButtons.OK); Application.Exit(); return; } var unit = units[0]; _unitId = unit.UnitId; Log(string.Format("Using unit id: {0}", _unitId)); Log(string.Format("Device instance id: {0}", unit.DeviceInstanceId)); Log(string.Format("Using database: {0}", DatabaseId)); // Check if we need to create a new database if (WinBioConfiguration.DatabaseExists(DatabaseId) == false) { InitialStart(); } else { OpenBiometricSession(); } }
private void buttonCaptureSample_Click(object sender, EventArgs e) { ThreadPool.QueueUserWorkItem(delegate { Bitmap image; WinBioRejectDetail rejectDetail; Log("Capturing sample..."); try { WinBio.CaptureSample(_session, WinBioBirPurpose.NoPurposeAvailable, WinBioBirDataFlags.Raw, out rejectDetail, out image); if (rejectDetail != WinBioRejectDetail.None) { Log(string.Format("CaptureSample failed! Reject detail: {0}", rejectDetail)); } else { Log("Captured sample successfully!"); this.fingerprintPictureBox.BackgroundImage = image; } } catch (WinBioException ex) { Log(ex); } }); }
private void OpenBiometricSession() { var units = WinBio.EnumBiometricUnits(WinBioBiometricType.Fingerprint); _unitId = units.FirstOrDefault().UnitId; _session = WinBio.OpenSession(WinBioBiometricType.Fingerprint, WinBioPoolType.Private, WinBioSessionFlag.Basic, new[] { _unitId }, Shared.DatabaseId); WriteLog("Session opened: " + _session.Value); }
public void CaptureSample(WinBioBirPurpose purpose, WinBioBirDataFlags dataFlags) { Bitmap image; WinBioRejectDetail rejectDetail; var unitId = WinBio.CaptureSample(_handle, purpose, dataFlags, out rejectDetail, out image); Console.WriteLine("Unit id: {0}", unitId); Console.WriteLine("Captured sample size: {0}x{1}", image.Width, image.Height); Console.WriteLine("Reject details: {0}", rejectDetail); }
private void WinBioForm_FormClosing(object sender, FormClosingEventArgs e) { if (!_session.IsValid) { return; } WinBio.CloseSession(_session); _session.Invalidate(); Log("Session closed"); }
protected override void OnFormClosing(FormClosingEventArgs e) { if (!_session.IsValid) { return; } WinBio.CloseSession(_session); _session.Invalidate(); Log("Session closed"); }
private void btnRebuildDatabase_Click(object sender, EventArgs e) { // Close existing session if (_session.IsValid) { WinBio.Cancel(_session); } InitialStart(); }
public void CaptureSample(WinBioBirPurpose purpose, WinBioBirDataFlags dataFlags) { int sampleSize; WinBioRejectDetail rejectDetail; var unitId = WinBio.CaptureSample(_handle, purpose, dataFlags, out sampleSize, out rejectDetail); Console.WriteLine("Unit id: {0}", unitId); Console.WriteLine("Captured sample size: {0}", sampleSize); Console.WriteLine("Reject details: {0}", rejectDetail); }
private void CloseWindow() { if (_session.IsValid) { WinBio.CloseSession(_session); _session.Invalidate(); } this.DialogResult = DialogResult.OK; this.Close(); }
private WinBioIdentity AddEnrollment(WinBioSessionHandle session, int unitId, WinBioBiometricSubType subType) { WriteLog(string.Format("Beginning enrollment of {0}:", subType)); WinBio.EnrollBegin(session, subType, unitId); var code = WinBioErrorCode.MoreData; WinBioRejectDetail rejectDetail; int good = 0; for (var swipes = 1; code != WinBioErrorCode.Ok; swipes++) { code = WinBio.EnrollCapture(session, out rejectDetail); switch (code) { case WinBioErrorCode.MoreData: WriteLog(string.Format("Swipe {0} was good", swipes)); good++; break; case WinBioErrorCode.BadCapture: WriteLog(string.Format("Swipe {0} was bad: {1}", swipes, rejectDetail)); break; case WinBioErrorCode.Ok: WriteLog(string.Format("Enrollment complete with {0} swipes", swipes)); break; default: throw new WinBioException(code, "WinBioEnrollCapture failed"); } Progress(good); } WriteLog("Committing enrollment.."); bool isNewTemplate; WinBioIdentity identity = null; try { isNewTemplate = WinBio.EnrollCommit(session, out identity); WriteLog(isNewTemplate ? "New template committed." : "Template already existing."); if (!isNewTemplate) { WinBio.Identify(session, out identity, out subType, out rejectDetail); } EnableDisableOk(true); } catch (Exception e) { WriteLog("Error on AddEnrollment. Error:" + e.Message); } return(identity); }
public void Identify() { WinBioIdentity identity; WinBioBiometricSubType subFactor; WinBioRejectDetail rejectDetail; var unitId = WinBio.Identify(_handle, out identity, out subFactor, out rejectDetail); Console.WriteLine("Unit Id: {0}", unitId); Console.WriteLine("Identity: {0}", identity); Console.WriteLine("Sub factor: {0}", subFactor); Console.WriteLine("Reject details: {0}", rejectDetail); }
public static void EnumDatabases() { var schemaArray = WinBio.EnumDatabases(WinBioBiometricType.Fingerprint); Console.WriteLine("Databases found: {0}", schemaArray.Length); for (var i = 0; i < schemaArray.Length; i++) { Console.WriteLine("Database {0}", i); var id = schemaArray[i].DatabaseId; Console.WriteLine("Id: {0}", id); } }
public void CloseBiometricSession() { Debug("Closing session..."); try { WinBio.CloseSession(_session); } catch (Exception e) { Debug("CloseBiometricSession error: " + e.Message); } UpdateStatus(Statuses.NoSession); }
private void buttonLocateSensor_Click(object sender, EventArgs e) { ThreadPool.QueueUserWorkItem(delegate { Log("Locating sensor..."); try { var unitId = WinBio.LocateSensor(_session); Log(string.Format("Sensor located: unit id {0}", unitId)); } catch (WinBioException ex) { Log(ex); } }); }
private void buttonLocateSensor_Click(object sender, EventArgs e) { ThreadPool.QueueUserWorkItem(delegate { Log("Locating sensor..."); try { _unitId = WinBio.LocateSensor(_session); Log(string.Format("Sensor located: unit id {0}", _unitId)); setComboxSelectedIndex(comboUnitId, comboUnitId.Items.IndexOf(_unitId)); } catch (WinBioException ex) { Log(ex); } }); }
protected override void OnShown(EventArgs e) { base.OnShown(e); if (StartEnrollment) { ThreadPool.QueueUserWorkItem(delegate { try { OpenBiometricSession(); var identity = AddEnrollment(_session, _unitId, WinBioBiometricSubType.RhIndexFinger); TemplateFingerGuid = identity.TemplateGuid; } catch (WinBioException ex) { WriteLog(ex.Message); } }); } else { ThreadPool.QueueUserWorkItem(delegate { OpenBiometricSession(); for (int i = 0; i < 5; i++) { try { WinBioIdentity identity; WinBioBiometricSubType subFactor; WinBioRejectDetail rejectDetail; WinBio.Identify(_session, out identity, out subFactor, out rejectDetail); TemplateFingerGuid = identity.TemplateGuid; this.Invoke(new Action(CloseWindow)); return; } catch (WinBioException ex) { WriteLog("Please retry!! Error:" + ex.Message); } } }); } }
private void RefreshReaderUnits() { cbReaderUnit.Items.Clear(); var units = WinBio.EnumBiometricUnits(WinBioBiometricType.Fingerprint); // Check if we have a connected fingerprint sensor if (units.Length == 0) { return; } foreach (var reader in units) { cbReaderUnit.Items.Add(new FingerprintUnit(reader.UnitId, reader.Description)); } cbReaderUnit.SelectedIndex = 0; }
private void IdentifyTheKeyLED_Click(object sender, EventArgs e) { ThreadPool.QueueUserWorkItem(delegate { try { WinBioRejectDetail rejectDetail; Log(string.Format("Please touch session: unit id {0} in flashing", _unitId)); WinBio.EnrollBegin(_session, WinBioBiometricSubType.LhThumb, _unitId); WinBio.EnrollCapture(_session, out rejectDetail); WinBio.EnrollDiscard(_session); Log(string.Format("Done")); } catch (WinBioException ex) { //ignore } }); }
private void buttonDelete_Click(object sender, EventArgs e) { if (_identity == null) { Log(string.Format("Please do Identity first.")); } else { try { WinBio.DeleteTemplate(_session, _unitId, _identity, (WinBioBiometricSubType)comboBoxFp.SelectedIndex); Log(string.Format("Delete Done.")); } catch (WinBioException ex) { Log(ex); } } }
protected override void OnLoad(EventArgs e) { var units = WinBio.EnumBiometricUnits(WinBioBiometricType.Fingerprint); Log(string.Format("Found {0} units", units.Length)); if (units.Length == 0) { return; } var unit = units[0]; _unitId = unit.UnitId; Log(string.Format("Using unit id: {0}", _unitId)); Log(string.Format("Device instance id: {0}", unit.DeviceInstanceId)); Log(string.Format("Using database: {0}", DatabaseId)); _session = WinBio.OpenSession(WinBioBiometricType.Fingerprint, WinBioPoolType.Private, WinBioSessionFlag.Basic, new[] { _unitId }, DatabaseId); //_session = WinBio.OpenSession(WinBioBiometricType.Fingerprint); Log("Session opened: " + _session.Value); }
private void buttonEnroll_Click(object sender, EventArgs e) { WinBioBiometricSubType subType = (WinBioBiometricSubType)comboBoxFp.SelectedIndex; if (subType == WinBioBiometricSubType.Unknown) { Log("Please select a finger index, not Unknown."); return; } ThreadPool.QueueUserWorkItem(delegate { try { Log("Put your finger on sensor..."); WinBioBiometricSubType subFactor; WinBioRejectDetail rejectDetail; while (true) { _unitId = WinBio.Identify(_session, out _identity, out subFactor, out rejectDetail); Log("No. This finger has been enrolled before. Change another one..."); } } catch (WinBioException ex) { Log("OK. This finger not yet be enrolled before."); } try { _identity = AddEnrollment(_session, _unitId, subType); Log(string.Format("Identity: {0}", _identity)); } catch (WinBioException ex) { Log(ex); if (ex.ErrorCode == WinBioErrorCode.DuplicateEnrollment) { Log(string.Format("Please select another finger index or just delete it for a new one.")); } } }); }
private void buttonIdentify_Click(object sender, EventArgs e) { ThreadPool.QueueUserWorkItem(delegate { Log("Identifying user..."); try { WinBioIdentity identity; WinBioBiometricSubType subFactor; WinBioRejectDetail rejectDetail; WinBio.Identify(_session, out identity, out subFactor, out rejectDetail); Log(string.Format("Identity: {0}", identity)); } catch (WinBioException ex) { Log(ex); } }); }
public bool ReleaseFocus() { Debug("Releasing focus..."); try { WinBioErrorCode result = WinBio.ReleaseFocus(); Debug(result.ToString()); if (result == WinBioErrorCode.Ok) { UpdateStatus(Statuses.NoFocus); } return(result == WinBioErrorCode.Ok); } catch (Exception) { return(false); } }
public static void EnumUnitIds() { var units = WinBio.EnumBiometricUnits(WinBioBiometricType.Fingerprint); Console.WriteLine("Biometric units found: {0}", units.Length); for (var i = 0; i < units.Length; i++) { Console.WriteLine(units[i].UnitId); Console.WriteLine(units[i].PoolType); Console.WriteLine(units[i].BiometricFactor); Console.WriteLine(units[i].SensorSubType); Console.WriteLine(units[i].Capabilities); Console.WriteLine(units[i].DeviceInstanceId); Console.WriteLine(units[i].Description); Console.WriteLine(units[i].Manufacturer); Console.WriteLine(units[i].Model); Console.WriteLine(units[i].SerialNumber); Console.WriteLine(units[i].FirmwareVersion); } }