/// <summary> /// /// compares stored hash to Hash generated from user info. /// if true, let them through /// if false error occurred /// </summary> /// <param name="FN">First Name</param> /// <param name="LN">Last Name</param> /// <param name="DOB">Date of Birth</param> /// <param name="Cntry">Country</param> /// <param name="rgn">Region</param> /// <param name="adrs">address</param> /// <param name="eml">email</param> /// <returns></returns> public static bool CheckHashTable(string FN, string LN, DateTime DOB, string Cntry, string rgn, string adrs, string eml) { int id = FindID(FN, LN); string inputString = FN + LN + DOB + Cntry + rgn + adrs; byte[] DataReceived = Encoding.UTF8.GetBytes(inputString); byte[] GeneratedHash; VoterInfo hashtable; if (id != -1) { hashtable = ElectionDBClass.RetrieveVoterInfoObject(id); } else { return(false); } DataTable dt = new DataTable(); byte[] salt = hashtable.Salt; //generates a SaltedHash with the datareceived, this is to allow for a comparison between the hash on the database and the new generated hash. A hash generated with key 'A' should always create Hash 'A'. So if hash 'A' != hash 'B', then then means one of two things: key 'a' != key 'b', or there is an error in logic some where. GeneratedHash = GenerateSaltedHash(DataReceived, salt); if (CompareByteArrays(hashtable.Hash, GeneratedHash)) //CompareByteArrays compares byte[] Summary: checks if ID's match, if true; generates saltedhash with hash on table. { return(true); } return(false); }
protected void btnSubmit_Click(object sender, EventArgs e) { if (ViewState["Mayor"] != null) { string[] tokens = ((string)ViewState["Mayor"]).Split(new char[] { ',' }); Candidate candidate = new Candidate(); candidate.LName = tokens[0]; candidate.FName = tokens[1]; ElectionDBClass.AddVoteToCandidate(candidate); } if (ViewState["CityCouncil"] != null) { string[] tokens = ((string)ViewState["CityCouncil"]).Split(new char[] { ',' }); Candidate candidate = new Candidate(); candidate.LName = tokens[0]; candidate.FName = tokens[1]; ElectionDBClass.AddVoteToCandidate(candidate); } if (ViewState["Superintendent"] != null) { string[] tokens = ((string)ViewState["Superintendent"]).Split(new char[] { ',' }); Candidate candidate = new Candidate(); candidate.LName = tokens[0]; candidate.FName = tokens[1]; ElectionDBClass.AddVoteToCandidate(candidate); } }
/// <summary> /// Hopefully this function will find the ID from Firstname and LastName, will return -1 if it can't find id. /// </summary> /// <param name="FN"> FirstName</param> /// <param name="LN"> LastName</param> /// <returns></returns> private static int FindID(string FN, string LN) { int id = -1; DataTable aaa = ElectionDBClass.VotersTable(); foreach (DataRow dr in aaa.Rows) { if (dr[1].ToString() == FN && dr[2].ToString() == LN) { id = (int)dr[Convert.ToInt32(0)]; break; } else { return(-1); } } return(id); }