private void LoginBtn_Click(object sender, EventArgs e) { using (LeafSecurityEntities db = new LeafSecurityEntities()) { AccountInformation adminAccount = (from account in db.AccountInformations where account.AccountNumber == usernameTxt.Text && account.TypeID.Equals(1) select account).FirstOrDefault(); if (adminAccount == null) { MessageBox.Show("Account doesn't exist. Try again.", "Account doesn't exist", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (adminAccount.AccountUsername != passwordTxt.Text) { MessageBox.Show("Password incorrect, Try again.", "Alert! Enterd Password Wrong", MessageBoxButtons.OK, MessageBoxIcon.Error); } else // If User Authenticated { dash.Show(); this.Close(); } } }
private void populateAccountList(string keyword) { keyword = keyword.ToLower(); using (LeafSecurityEntities db = new LeafSecurityEntities()) { IEnumerable <AccountInformation> accounts = from account in db.AccountInformations where account.AccountNumber.Contains(keyword) || account.AccountUsername.Contains(keyword) || account.AccountID.ToString().Contains(keyword) select account; IEnumerable <AccountInformation> users = from user in db.UserInformations where user.FirstName.ToLower().Contains(keyword) || user.LastName.ToLower().Contains(keyword) || user.Email.ToLower().Contains(keyword) || user.PhoneNumber.ToLower().Contains(keyword) || user.Address.ToLower().Contains(keyword) select user.AccountInformation; foreach (AccountInformation account in accounts.Union(users)) { // Getting Account Type AccountType accType = (from aType in db.AccountTypes select aType).First(a => a.TypeID == account.TypeID); // Getting User Information UserInformation userInfo = (from user in db.UserInformations //where user.AccountID == account.AccountID select user).First(a => a.AccountID == account.AccountID); // Getting FingerprintTemplate IEnumerable <FingerprintTemplate> tFingerprint = (from tFinger in db.FingerprintTemplates where tFinger.AccountID == account.AccountID select tFinger); ListViewItem accountItem = new ListViewItem(); accountItem.Text = account.AccountID.ToString(); ListViewItem.ListViewSubItemCollection accountSubItemCollection = new ListViewItem.ListViewSubItemCollection(accountItem); accountSubItemCollection.Add(userInfo.FirstName + " " + userInfo.LastName); accountSubItemCollection.Add(accType.TypeName); accountSubItemCollection.Add(userInfo.Address); accountSubItemCollection.Add(userInfo.PhoneNumber); if (tFingerprint.Count().Equals(0)) { accountSubItemCollection.Add("No"); } else { accountSubItemCollection.Add("Yes"); } accountList.Items.Add(accountItem); } } }
private bool removeAccount(int accountID) { using (LeafSecurityEntities db = new LeafSecurityEntities()) { AccountInformation account = (from acc in db.AccountInformations where acc.AccountID.Equals(accountID) select acc).FirstOrDefault(); // If there are no accounts if (account == null) { return(false); } /** * We don't want to remove access to the main account. */ // Disabling Removing Main Admin Account if (account.AccountID == 1) { return(false); } UserInformation userInfo = (from user in db.UserInformations where user.AccountID.Equals(account.AccountID) select user).Single(); IEnumerable <FingerprintTemplate> fTemplates = (from fTemp in db.FingerprintTemplates where fTemp.AccountID.Equals(account.AccountID) select fTemp); fTemplates.ToList().ForEach(t => { db.MinutiaeTemplatePaths.Remove(t.MinutiaeTemplatePath); }); db.FingerprintTemplates.RemoveRange(fTemplates); db.UserInformations.Remove(userInfo); db.AccountInformations.Remove(account); db.SaveChanges(); } return(true); }
private void generateAccountNumber() { int newAccountNumber = RandomGen.Generate.RandomNumber(10000000, 99999999); using (LeafSecurityEntities db = new LeafSecurityEntities()) { IEnumerable <AccountInformation> acc = from account in db.AccountInformations where account.AccountNumber .ToString() .Equals(newAccountNumber.ToString()) select account; if (!acc.Count().Equals(0)) { newAccountNumber = RandomGen.Generate.RandomNumber(1000, 9999); } } usernameTxt.Text = newAccountNumber.ToString(); }
private void editAccount() { Console.WriteLine("Selected (Editing) Indices: {0}", accountList.SelectedIndices[0]); if (accountList.SelectedIndices.Count.Equals(0)) { return; } ListViewItem selectedItem = accountList.SelectedItems[0]; int accID = Convert.ToInt32(selectedItem.Text); AccountInformation selectedAccount; using (LeafSecurityEntities db = new LeafSecurityEntities()) { selectedAccount = (from acc in db.AccountInformations where acc.AccountID.Equals(accID) select acc).FirstOrDefault(); } AccountForm accForm = new AccountForm(selectedAccount); accForm.Show(); }
private void AccountForm_Load(object sender, EventArgs e) { // Adding AccountTypes to Selection ComboBox using (LeafSecurityEntities db = new LeafSecurityEntities()) { // Populating ComboList with AccountType(s). foreach (AccountType aType in db.AccountTypes) { accountTypeCombo.Items.Add(aType.TypeName); } if (m_accountInformation != null) { // Gathering User Information UserInformation userInfo = (from acc in db.UserInformations where acc.AccountID == m_accountInformation.AccountID select acc).First(); int accType = userInfo.AccountInformation.AccountType.TypeID; // Setting up AccountForm() // User Information firstNameTxt.Text = userInfo.FirstName.ToString(); lastNameTxt.Text = userInfo.LastName; if (userInfo.Email != null) { emailTxt.Text = userInfo.Email; } if (userInfo.PhoneNumber != null) { phoneNumberTxt.Text = userInfo.PhoneNumber; } if (userInfo.Address != null) { addressTxt.Text = userInfo.Address; } // If Admin Account Selected if (accType.Equals(1)) { accountTypeCombo.SelectedItem = accountTypeCombo.Items[0]; passwordTxt.Text = m_accountInformation.AccountUsername; confirmPasswordTxt.Text = m_accountInformation.AccountUsername; stringHashTxt.Text = "Admin Account Doesn't Contain This Item."; } // If User Account Seleted else { accountTypeCombo.SelectedIndex = 1; passwordTxt.Text = m_accountInformation.AccountUsername; } // AccountInformation usernameTxt.Text = userInfo.AccountInformation.AccountNumber; // BiometricInformation if (accType.Equals(2)) { // Gathering Fingerprint Information FingerprintTemplate fingerTemplate = (from acc in db.FingerprintTemplates where acc.AccountID == m_accountInformation.AccountID select acc).First(); // Only works for User Accounts stringHashTxt.Text = Path.GetFileName(fingerTemplate.MinutiaeTemplatePath.TemplatePath); generateHashBtn.Enabled = false; } } } // Enabling Sensor(s) m_FPM = new SGFingerPrintManager(); device_name = SGFPMDeviceName.DEV_FDU03; // ...Initializing Port Address port_addr = (Int32)SGFPMPortAddr.USB_AUTO_DETECT; // ...Initializing Device (HSDUO03P) m_FPM.Init(device_name); iError = m_FPM.OpenDevice(port_addr); fingerprint_device_connected = true; if (iError != (Int32)SGFPMError.ERROR_NONE) { //DialogResult res = MessageBox.Show(this, "Are you sure you have a fingerprint sensor connected?", // "Fingerprint Sensor not Connected", MessageBoxButtons.OK, MessageBoxIcon.Error); //Console.WriteLine("OpenDevice() Error : " + iError); fingerprint_device_connected = false; } if (fingerprint_device_connected) { // Hiding Some Controls, // These controls are only used when fingerprint is not available. imageFilePath.Hide(); templatePathLbl.Hide(); openTempFileBtn.Hide(); groupBox3.Height = 450; // ...Enabling Auto-On Feature m_FPM.EnableAutoOnEvent(true, (int)this.Handle); AutoReadFingerprint_chk.Checked = true; // Getting Device Info SGFPMDeviceInfoParam pInfo = new SGFPMDeviceInfoParam(); pInfo = new SGFPMDeviceInfoParam(); iError = m_FPM.GetDeviceInfo(pInfo); if (iError == (Int32)SGFPMError.ERROR_NONE) { img_w = pInfo.ImageWidth; img_h = pInfo.ImageHeight; img_dpi = pInfo.ImageDPI; } } else { // Hiding Some Controls, // These controls are only used when fingerprint is available. FingerprintPreviewBox.Hide(); AutoReadFingerprint_chk.Hide(); ReadFingerprintBtn.Hide(); fingerprint_preview_lbl.Hide(); } // disabling buttons that are used afer selecting account type AutoReadFingerprint_chk.Checked = false; AutoReadFingerprint_chk.Enabled = false; FingerprintPreviewBox.Hide(); copyHashBtn.Enabled = false; ReadFingerprintBtn.Enabled = false; openTempFileBtn.Enabled = false; imageFilePath.Enabled = false; }
private void doneBtn_Click(object sender, EventArgs e) { errorEncountered = false; using (LeafSecurityEntities db = new LeafSecurityEntities()) { // Checking Personal Information Data. (First Name) if (firstNameTxt.Text.Length.Equals(0)) { errorEncountered = true; firstNameLbl.ForeColor = Color.Red; errorLbl.Show(); } // Checking Personal Information Data. (Last Name) if (lastNameTxt.Text.Length.Equals(0)) { errorEncountered = true; lastNameLbl.ForeColor = Color.Red; errorLbl.Show(); } // Checking Personal Information Data. (Email) if (emailTxt.Text.Length.Equals(0)) { inputTab.SelectTab(0); emailLbl.ForeColor = Color.Blue; DialogResult result = MessageBox.Show("Are you sure you want to leave some fields blank", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { errorEncountered = true; } } // Checking Personal Information Data. (Phone Number) if (phoneNumberTxt.Text.Length.Equals(0)) { inputTab.SelectTab(0); phoneNumberLbl.ForeColor = Color.Blue; DialogResult result = MessageBox.Show("Are you sure you want to leave some fields blank", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { errorEncountered = true; } } // Checking Personal Information Data. if (addressTxt.Text.Length.Equals(0)) { inputTab.SelectTab(0); addressLbl.ForeColor = Color.Blue; DialogResult result = MessageBox.Show("Are you sure you want to leave some fields blank", "Are you sure?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.No) { errorEncountered = true; } } // Checking Account Data IEnumerable <AccountInformation> anotherAcc = from acc in db.AccountInformations where acc.AccountNumber == usernameTxt.Text select acc; if (!anotherAcc.Count().Equals(0)) { errorEncountered = true; usernameLbl.ForeColor = Color.Red; usernameErrorTooltip.SetToolTip(this.usernameLbl, "User name exists"); usernameErrorTooltip.SetToolTip(this.usernameTxt, "User name exists"); errorLbl.Show(); } if (usernameTxt.Text.Length.Equals(0)) { errorEncountered = true; usernameLbl.ForeColor = Color.Red; usernameErrorTooltip.SetToolTip(this.usernameLbl, "User name not entered."); usernameErrorTooltip.SetToolTip(this.usernameTxt, "User name not entered."); errorLbl.Show(); } if (passwordTxt.Text.Length.Equals(0)) { errorEncountered = true; passwordLbl.ForeColor = Color.Red; confirmPasswordLbl.ForeColor = Color.Red; passwordErrorTooltip.SetToolTip(this.passwordLbl, "Password not entered."); passwordErrorTooltip.SetToolTip(this.confirmPasswordLbl, "Password not entered."); passwordErrorTooltip.SetToolTip(this.passwordTxt, "Password not entered."); passwordErrorTooltip.SetToolTip(this.confirmPasswordTxt, "Password not entered."); errorLbl.Show(); } if (!passwordTxt.Text.Equals(confirmPasswordTxt.Text) && accountTypeCombo.SelectedIndex.Equals(0)) { errorEncountered = true; passwordLbl.ForeColor = Color.Red; confirmPasswordLbl.ForeColor = Color.Red; passwordErrorTooltip.SetToolTip(this.passwordLbl, "Password does not match."); passwordErrorTooltip.SetToolTip(this.confirmPasswordLbl, "Password does not match."); passwordErrorTooltip.SetToolTip(this.passwordTxt, "Password does not match."); passwordErrorTooltip.SetToolTip(this.confirmPasswordTxt, "Password does not match."); errorLbl.Show(); } if (accountTypeCombo.SelectedIndex == -1) { errorEncountered = true; accountTypeLbl.ForeColor = Color.Red; accountTypeErrorTooltip.SetToolTip(this.accountTypeLbl, "Account type not selected."); accountTypeErrorTooltip.SetToolTip(this.accountTypeCombo, "Account type not selected."); } // Checking Template Information // If account type does require fingerprint template if (!accountTypeCombo.SelectedIndex.Equals(0)) { // If template file not provided // and If template is nessesary, meaning fingerprint sensor is not connected if (imageFilePath.Text.Length.Equals(0) && !fingerprint_device_connected) { errorEncountered = true; templatePathLbl.ForeColor = Color.Red; templatePathErrorTooltip.SetToolTip(this.templatePathLbl, "Template not provided."); errorLbl.Show(); } if (!File.Exists(imageFilePath.Text) && !fingerprint_device_connected) { errorEncountered = true; templatePathLbl.ForeColor = Color.Red; templatePathErrorTooltip.SetToolTip(this.templatePathLbl, "Template file doest not exist."); errorLbl.Show(); } // if Fingerprint Sensor is connected but // fingerprint not read yet. if (!this.fingerprintTaken) { errorEncountered = true; fingerprint_preview_lbl.ForeColor = Color.Red; templatePathErrorTooltip.SetToolTip(this.fingerprint_preview_lbl, "Fingerprint Not Provided."); errorLbl.Show(); } } // Entering Verified Data if (!errorEncountered) { if (accountTypeCombo.SelectedIndex.Equals(0)) { // Account Information AccountInformation accountInfo = new AccountInformation(); accountInfo.AccountNumber = usernameTxt.Text; accountInfo.AccountUsername = passwordTxt.Text; accountInfo.TypeID = 1; // Since Account Type 'Admin' is identified as 1 accountInfo.AccountCreationDate = DateTime.Now; db.AccountInformations.Add(accountInfo); db.SaveChanges(); Console.WriteLine("Account ID: {0}", accountInfo.AccountID); // User Information UserInformation userInformation = new UserInformation(); //userInformation.AccountID = (from accTemp in db.AccountInformations // where accTemp.AccountNumber == accountInfo.AccountNumber // select accTemp).First().AccountID; userInformation.AccountID = accountInfo.AccountID; userInformation.FirstName = firstNameTxt.Text; userInformation.LastName = lastNameTxt.Text; userInformation.PhoneNumber = phoneNumberTxt.Text; userInformation.Email = emailTxt.Text; userInformation.Address = addressTxt.Text; db.UserInformations.Add(userInformation); db.SaveChanges(); MessageBox.Show(String.Format("User {0} added to database.", userInformation.FirstName + " " + userInformation.LastName), "User successfully added to database", MessageBoxButtons.OK, MessageBoxIcon.Information); Console.WriteLine("User ID: {0}", userInformation.UserID); Console.WriteLine("Account added to database."); } // If User Account Type is created. else if (accountTypeCombo.SelectedIndex.Equals(1)) { // Account Information AccountInformation accountInfo = new AccountInformation(); accountInfo.AccountNumber = usernameTxt.Text; accountInfo.AccountUsername = passwordTxt.Text; accountInfo.TypeID = 2; // Since Account Type 'User' is identified as 2 accountInfo.AccountCreationDate = DateTime.Now; db.AccountInformations.Add(accountInfo); db.SaveChanges(); Console.WriteLine("Account ID: {0}", accountInfo.AccountID); // User Information UserInformation userInformation = new UserInformation(); //userInformation.AccountID = (from accTemp in db.AccountInformations // where accTemp.AccountNumber == accountInfo.AccountNumber // select accTemp).First().AccountID; userInformation.AccountID = accountInfo.AccountID; userInformation.FirstName = firstNameTxt.Text; userInformation.LastName = lastNameTxt.Text; userInformation.PhoneNumber = phoneNumberTxt.Text; userInformation.Email = emailTxt.Text; userInformation.Address = addressTxt.Text; db.UserInformations.Add(userInformation); db.SaveChanges(); // Minutiae TemplatePath Information DirectoryOps.DefaultApplicationDirectory appDatabaseDir = new DirectoryOps.DefaultApplicationDirectory(Program.defaultApplicationDatabaseDirName); DirectoryOps.DefaultApplicationDirectory matlabGeneratedDir = new DirectoryOps.DefaultApplicationDirectory(Program.defaultMatlabGeneratedDirName); /* Declaring variables used to store: * tempFingerprintFileName - Temporary Fingerprint File from fingerprint sensor. * generatedTemplateFileName - Matlab Generated Minutiea Template File. * */ string tempFingerprintFileName; string generatedTemplateFileName; // Generating Template file using matlab // If fingerprint sensor is connected, generateTemplate() using sensor image // else use fingerprint image from image file if (fingerprint_device_connected) { tempFingerprintFileName = saveFingerprintImage(); generatedTemplateFileName = generateTemplate(tempFingerprintFileName); } else { generatedTemplateFileName = generateTemplate(); } try { if (FileOps.FileOperation.Save( Path.Combine(matlabGeneratedDir.Path, generatedTemplateFileName), appDatabaseDir.Path, stringHashTxt.Text)) { Console.WriteLine("File saved as: {0}", Path.Combine(appDatabaseDir.Path, stringHashTxt.Text)); } } catch (Exception exc) { MessageBox.Show( exc.Message, "Exception Occured!", MessageBoxButtons.OK, MessageBoxIcon.Warning ); } MinutiaeTemplatePath minutiaeTemplatePath = new MinutiaeTemplatePath(); minutiaeTemplatePath.TemplatePath = Path.Combine(appDatabaseDir.Path, stringHashTxt.Text); db.MinutiaeTemplatePaths.Add(minutiaeTemplatePath); db.SaveChanges(); // Template Information FingerprintTemplate fingerprintTemplate = new FingerprintTemplate(); fingerprintTemplate.AccountID = accountInfo.AccountID; fingerprintTemplate.MinutiaeTemplateID = minutiaeTemplatePath.ID; db.FingerprintTemplates.Add(fingerprintTemplate); db.SaveChanges(); MessageBox.Show(String.Format("User {0} added to database.", userInformation.FirstName + " " + userInformation.LastName), "User successfully added to database", MessageBoxButtons.OK, MessageBoxIcon.Information); Console.WriteLine("User ID: {0}", userInformation.UserID); Console.WriteLine("Account added to database."); this.Close(); } } } }