Пример #1
0
        private string generateTemplate()
        {
            DirectoryOps.DefaultApplicationDirectory matlabFunctionDir =
                new DirectoryOps.DefaultApplicationDirectory(Program.defaultMatlabFunctionDirName);

            // creating function object
            MatLabOps.MatLabOps.FunctionProperties func = new MatLabOps.MatLabOps.FunctionProperties();
            func.functionPath = matlabFunctionDir.Path;
            func.functionName = @"auto_generate_minutiae";
            func.nArgOut      = 1;

            // Gerated file name
            string tempName = RandomGen.Generate.RandomString(6, true);

            MatLabOps.MatLabOps.generateTemplate(func, Path.GetDirectoryName(imageFilePath.Text),
                                                 Path.GetFileName(imageFilePath.Text), tempName);

            return(tempName);
        }
Пример #2
0
        // Saves Fingerprint temporarily in
        // Application temp folder.
        private string saveFingerprintImage()
        {
            DirectoryOps.DefaultApplicationDirectory tempDir =
                new DirectoryOps.DefaultApplicationDirectory(Program.defaultApplicationTempDir);
            // Generating temporary file name for the fingerprint image.
            string tempFileName = RandomGen.Generate.RandomString(4, true);

            tempFileName += ".tif";
            // Creating an Image Object to save as file
            Bitmap bmp = new Bitmap(260, 300);

            FingerprintPreviewBox.DrawToBitmap(bmp, FingerprintPreviewBox.ClientRectangle);
            ImageConverter imgConverter = new ImageConverter();
            // Converting the 32bit Image to 8bit (Indexed) Greyscale Image
            Bitmap bmpGrey = new Bitmap(260, 300, PixelFormat.Format8bppIndexed);

            bmpGrey = bmp.Clone(new Rectangle(0, 0, 260, 300),
                                PixelFormat.Format8bppIndexed);
            // Saving the Image object as Image File.
            bmpGrey.Save(Path.Combine(tempDir.Path, tempFileName), ImageFormat.Bmp);
            return(tempFileName);
        }
Пример #3
0
        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();
                    }
                }
            }
        }
Пример #4
0
        public static bool Check(DashBoardForm dashboard)
        {
            // Creating directory objects for application folder
            DirectoryOps.DefaultApplicationDirectory defaultDir =
                new DirectoryOps.DefaultApplicationDirectory(Program.defaultApplicationDirName);
            DirectoryOps.DefaultApplicationDirectory defaultDatabaseDir =
                new DirectoryOps.DefaultApplicationDirectory(Program.defaultApplicationDatabaseDirName);
            DirectoryOps.DefaultApplicationDirectory defaultMatlabDir =
                new DirectoryOps.DefaultApplicationDirectory(Program.defaultMatlabFunctionDirName);
            DirectoryOps.DefaultApplicationDirectory defaultTempDir =
                new DirectoryOps.DefaultApplicationDirectory(Program.defaultApplicationTempDir);

            // Opening Operation Objects for each folder.
            DirectoryOps.DirectoryOperation dirOperations =
                new DirectoryOps.DirectoryOperation(defaultDir);
            DirectoryOps.DirectoryOperation dbDirOperations =
                new DirectoryOps.DirectoryOperation(defaultDatabaseDir);
            DirectoryOps.DirectoryOperation matlabDirOperations =
                new DirectoryOps.DirectoryOperation(defaultMatlabDir);
            DirectoryOps.DirectoryOperation tempDirOperations =
                new DirectoryOps.DirectoryOperation(defaultTempDir);

            // If application Folder and application database folder
            // do not exist create them.
            if (!dirOperations.Exists())
            {
                dirOperations.Create();
            }
            if (!dbDirOperations.Exists())
            {
                dbDirOperations.Create();
            }
            if (!matlabDirOperations.Exists())
            {
                matlabDirOperations.Create();
            }
            if (!tempDirOperations.Exists())
            {
                tempDirOperations.Create();
            }

            // Checking if Fingerprint Machine is Connected
            SGFingerPrintManager m_FPM       = new SGFingerPrintManager();
            SGFPMDeviceName      device_name = SGFPMDeviceName.DEV_FDU03;

            //...Initializing Port Address
            Int32 port_addr = (Int32)SGFPMPortAddr.USB_AUTO_DETECT;

            m_FPM.Init(device_name);
            Int32 iError = m_FPM.OpenDevice(port_addr);

            if (iError != (Int32)SGFPMError.ERROR_NONE)
            {
                DialogResult res = MessageBox.Show(dashboard, "Are you sure you want to continue with out a fingerprint sensor?",
                                                   "Fingerprint Sensor not Connected", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                Console.WriteLine("Openning Device Error : " + iError);
                if (res == DialogResult.No)
                {
                    dashboard.Close();
                    return(false);
                }
                dashboard.fp_device_connected(false); // Tell dashboard sensor is not connected
            }
            dashboard.fp_device_connected(true);      // Tell dashboard sensor is connected
            return(true);
        }