Ejemplo n.º 1
0
        public static void OpenDbConnection(bool isEncrypted)
        {
            string password = string.Empty;

            if (isEncrypted)
            {
                string username;
                byte[] ciphertext;
                byte[] entropy;

                if (PasswordUtility.RetrievePasswordFromRegistry(out username, out ciphertext, out entropy))
                {
                    password = PasswordUtility.Decrypt(ciphertext, entropy);
                }
            }

            SqliteCon = new SQLiteConnection(DbConnectionString);

            if (isEncrypted)
            {
                SqliteCon.SetPassword(password);
            }

            SqliteCon.Open();
        }
Ejemplo n.º 2
0
        private void LoginBtn_Click(object sender, RoutedEventArgs e)
        {
            LoginErrTxtBlk.Text = "";

            try
            {
                string storedUsername;
                byte[] storedCiphertext;
                byte[] storedEntropy;

                if (!PasswordUtility.RetrievePasswordFromRegistry(out storedUsername, out storedCiphertext, out storedEntropy))
                {
                    LoginErrTxtBlk.Text = "No username and password stored in the registry. Register first.";
                    Reset();
                }
                else
                {
                    if (PasswordUtility.Verify(usernameTxt.Text, passwordBox.Password))
                    {
                        LoginErrTxtBlk.Text = "Login successful";
                        mainWindow          = new MainWindow();
                        mainWindow.Show();
                        Close();
                    }
                    else
                    {
                        LoginErrTxtBlk.Text = "Incorrect username and/or password. Try again.";
                        Reset();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 3
0
        private void SubmitBtn_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (usernameTxt.Text.Length == 0)
                {
                    errormessage.Text = "Enter a username.";
                    usernameTxt.Focus();
                }
                else
                {
                    string username = usernameTxt.Text;
                    string password = passwordBox.Password;

                    if (passwordBox.Password.Length == 0)
                    {
                        errormessage.Text = "Enter password.";
                        passwordBox.Focus();
                    }
                    else if (passwordBoxConfirm.Password.Length == 0)
                    {
                        errormessage.Text = "Enter the Confirm password.";
                        passwordBoxConfirm.Focus();
                    }
                    else if (passwordBox.Password != passwordBoxConfirm.Password)
                    {
                        errormessage.Text = "Confirm password must be same as password.";
                        passwordBoxConfirm.Focus();
                    }
                    else
                    {
                        errormessage.Text = string.Empty;

                        //check if username already exists. Go back to login.
                        string savedUsername;
                        byte[] ciphertext;
                        byte[] entropy;

                        if (PasswordUtility.RetrievePasswordFromRegistry(out savedUsername, out ciphertext, out entropy))
                        {
                            errormessage.Text = "The software is already registered to a user. " +
                                                "Please login with the username and password used to register the software.";
                            Reset();
                        }
                        else
                        {
                            PasswordUtility.Encrypt(passwordBox.Password, out ciphertext, out entropy);
                            PasswordUtility.StorePasswordInRegistry(username, ciphertext, entropy);
                            DatabaseInfo.SetPassword(passwordBox.Password);
                            errormessage.Text = "You have registered successfully.";
                            Reset();
                            mainWindow = new MainWindow();
                            mainWindow.Show();
                            Close();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }