public void AddFingerprint(FingerprintCard card, Image newprint) { using (var newconnect = new DbConnection()) { if (!newconnect.Connect()) { throw new CannotConnectToDatabaseException(); } string query; if (card.FingerprintList.Count == 0) //card is empty => register new card { query = "insert into usertbl values(\"" + card.guid + "\",\"" + card.FirstName + "\",\"" + card.LastName + "\");"; newconnect.SendQueryAndClose(query); } query = "insert into fprinttbl values(?File,\"" + card.guid + "\");"; byte[] rawimg = SerializeImage(newprint); MySqlParameter pFile = new MySqlParameter("?File", rawimg); newconnect.SendQueryAndClose(query, pFile); card.FingerprintList.Add(newprint); } CachedDB.UpdateCard(card); }
public FingerprintCard[] GetFingerprints() { FingerprintCard[] resultarray = CachedDB.getCacheDb(); //getCache if (resultarray != null) { return(resultarray); } using (var newconnect = new DbConnection()) { if (!newconnect.Connect()) { throw new CannotConnectToDatabaseException(); } string query = "select * from usertbl;"; MySqlDataReader reader = newconnect.SendQuery(query); List <FingerprintCard> fingerprintlist = new List <FingerprintCard>(); while (reader.Read()) { FingerprintCard newcard = new FingerprintCard(reader.GetValue(1).ToString(), reader.GetValue(2).ToString()); string guidstr = (string)reader.GetValue(0); newcard.guid = new Guid(guidstr); newcard.FingerprintList = GetFingerprintList(newcard.guid); fingerprintlist.Add(newcard); } reader.Close(); resultarray = fingerprintlist.ToArray(); } CachedDB.UpdateCache(resultarray); return(resultarray); }
public void AddFingerprint(FingerprintCard card, Image newprint) { using (var newconnect = new DbConnection()) { if (!newconnect.Connect()) throw new CannotConnectToDatabaseException(); string query; if (card.FingerprintList.Count == 0) //card is empty => register new card { query = "insert into usertbl values(\"" + card.guid + "\",\"" + card.FirstName + "\",\"" + card.LastName + "\");"; newconnect.SendQueryAndClose(query); } query = "insert into fprinttbl values(?File,\"" + card.guid + "\");"; byte[] rawimg = SerializeImage(newprint); MySqlParameter pFile = new MySqlParameter("?File", rawimg); newconnect.SendQueryAndClose(query, pFile); card.FingerprintList.Add(newprint); } CachedDB.UpdateCard(card); }
public void increaseCache() { capacity += 50; FingerprintCard[] newarray = new FingerprintCard[capacity]; Array.Copy(CachedDatabase, newarray, CachedDatabase.Length); CachedDatabase = newarray; }
public void UpdateCard(FingerprintCard fcard) { if (CachedDatabase == null) { return; // caching is redundant } bool found = false; for (int i = 0; i < loadfactor; ++i) { if (CachedDatabase[i].guid == fcard.guid) { CachedDatabase[i] = fcard; found = true; break; } } if (!found) { CachedDatabase[loadfactor] = fcard; ++loadfactor; } if (loadfactor == capacity) { increaseCache(); } }
/// <summary> /// Identification /// </summary> /// <param name="fingerprint">image of fingerprint to identificate </param> /// <param name="cards"></param> /// <returns></returns> public FingerprintCard Identify(Image fingerprint, FingerprintCard[] cards) { int numberOfVerified = 0; FingerprintCard identifiedCard = null; #region paranoia section if (fingerprint == null) { throw new ArgumentNullException("fingerprint"); } if (cards == null) { throw new ArgumentNullException("cards"); } #endregion foreach (FingerprintCard card in cards) { #region paranoia section if (card == null) { throw new ArgumentNullException("card"); } if (card.FingerprintList == null) { throw new ArgumentNullException("card.FingerprintList"); } if (card.FingerprintList.Count == 0) { throw new ArgumentOutOfRangeException("card.FingerprintList.Count"); } #endregion // If successfuly verified if (Verify(fingerprint, card)) { identifiedCard = card; numberOfVerified++; if (numberOfVerified > 1 || numberOfVerified < 0) { throw new Exception("Oh shi~! Here is some critical security error!" + "For current image successfuly verified more than one fingercard!"); } } } // Decide what to return switch (numberOfVerified) { case 0: return(null); case 1: return(identifiedCard); default: throw new Exception("You shouldn't be here!"); } }
public FingerprintCard[] getCacheDb() { if (CachedDatabase == null) { return(null); } FingerprintCard[] returnarray = new FingerprintCard[loadfactor]; Array.Copy(CachedDatabase, returnarray, loadfactor); return(returnarray); }
/// <summary> /// Verification /// </summary> /// <param name="fingerprint">image of fingerprint to verify</param> /// <param name="card">card</param> /// <returns>true if success, otherwise false</returns> public bool Verify(Image fingerprint, FingerprintCard card) { // The best verification score reached int maxScore = 0; #region paranoia section if (fingerprint == null) { throw new ArgumentNullException("fingerprint"); } if (card == null) { throw new ArgumentNullException("card"); } if (card.FingerprintList == null) { throw new ArgumentNullException("card.FingerprintList"); } if (card.FingerprintList.Count == 0) { throw new ArgumentOutOfRangeException("card.FingerprintList.Count"); } #endregion FingerprintTemplate templateToVerify; FingerprintRawImage rawImageToVerify = RawImageFromImage(fingerprint); templateToVerify = ExtractTemplate(rawImageToVerify); foreach (Image tempImage in card.FingerprintList) { FingerprintTemplate templateTemp; FingerprintRawImage rawImageTemp = RawImageFromImage(tempImage); templateTemp = ExtractTemplate(rawImageTemp); int result; fingerPrintCore.Verify(templateToVerify, templateTemp, out result); if (result > maxScore) { maxScore = result; } } // If success... if (maxScore >= Settings.Default.GriauleMatcherMinScoreToSuccessVerify) { return(true); } // If failed... return(false); }
public FingerprintCard[] GetFingerprints() { FingerprintCard[] resultarray = CachedDB.getCacheDb(); //getCache if (resultarray != null) return resultarray; using (var newconnect = new DbConnection()) { if (!newconnect.Connect()) throw new CannotConnectToDatabaseException(); string query = "select * from usertbl;"; MySqlDataReader reader = newconnect.SendQuery(query); List<FingerprintCard> fingerprintlist = new List<FingerprintCard>(); while (reader.Read()) { FingerprintCard newcard = new FingerprintCard(reader.GetValue(1).ToString(), reader.GetValue(2).ToString()); string guidstr = (string)reader.GetValue(0); newcard.guid = new Guid(guidstr); newcard.FingerprintList = GetFingerprintList(newcard.guid); fingerprintlist.Add(newcard); } reader.Close(); resultarray = fingerprintlist.ToArray(); } CachedDB.UpdateCache(resultarray); return resultarray; }
/// <summary> /// Identification /// </summary> /// <param name="fingerprint">image of fingerprint to identificate </param> /// <param name="cards"></param> /// <returns></returns> public FingerprintCard Identify(Image fingerprint, FingerprintCard[] cards) { int numberOfVerified = 0; FingerprintCard identifiedCard = null; #region paranoia section if (fingerprint == null) throw new ArgumentNullException("fingerprint"); if (cards == null) throw new ArgumentNullException("cards"); #endregion foreach (FingerprintCard card in cards) { #region paranoia section if (card == null) throw new ArgumentNullException("card"); if (card.FingerprintList == null) throw new ArgumentNullException("card.FingerprintList"); if (card.FingerprintList.Count == 0) throw new ArgumentOutOfRangeException("card.FingerprintList.Count"); #endregion // If successfuly verified if (Verify(fingerprint, card)) { identifiedCard = card; numberOfVerified++; if (numberOfVerified > 1 || numberOfVerified < 0) { throw new Exception("Oh shi~! Here is some critical security error!" + "For current image successfuly verified more than one fingercard!"); } } } // Decide what to return switch (numberOfVerified) { case 0: return null; case 1: return identifiedCard; default: throw new Exception("You shouldn't be here!"); } }
/// <summary> /// Verification /// </summary> /// <param name="fingerprint">image of fingerprint to verify</param> /// <param name="card">card</param> /// <returns>true if success, otherwise false</returns> public bool Verify(Image fingerprint, FingerprintCard card) { // The best verification score reached int maxScore = 0; #region paranoia section if (fingerprint == null) throw new ArgumentNullException("fingerprint"); if (card == null) throw new ArgumentNullException("card"); if (card.FingerprintList == null) throw new ArgumentNullException("card.FingerprintList"); if (card.FingerprintList.Count == 0) throw new ArgumentOutOfRangeException("card.FingerprintList.Count"); #endregion FingerprintTemplate templateToVerify; FingerprintRawImage rawImageToVerify = RawImageFromImage(fingerprint); templateToVerify = ExtractTemplate(rawImageToVerify); foreach (Image tempImage in card.FingerprintList) { FingerprintTemplate templateTemp; FingerprintRawImage rawImageTemp = RawImageFromImage(tempImage); templateTemp = ExtractTemplate(rawImageTemp); int result; fingerPrintCore.Verify(templateToVerify, templateTemp, out result); if (result > maxScore) maxScore = result; } // If success... if (maxScore >= Settings.Default.GriauleMatcherMinScoreToSuccessVerify) return true; // If failed... return false; }