Example #1
0
        private void bttnOk_Click(object sender, EventArgs e)
        {
            Dictionary <Credential.UserDataType, string> userDataDictionary = new Dictionary <Credential.UserDataType, string>();

            if (string.IsNullOrEmpty(txtBoxTitle.Text))
            {
                MessageBox.Show("Title has to be set!", "Edit Entry Error", MessageBoxButtons.OK);
                return;
            }

            if (string.IsNullOrEmpty(txtBoxPrimary.Text))
            {
                MessageBox.Show("Primary Login has to be set!", "Edit Entry Error", MessageBoxButtons.OK);
                return;
            }

            //if (string.IsNullOrEmpty(txtBoxWebsite.Text))
            //{
            //  MessageBox.Show("Website has to be set!", "Edit Entry Error", MessageBoxButtons.OK);
            //  return;
            //}

            if (string.IsNullOrEmpty(txtBoxPassword.Text))
            {
                MessageBox.Show("Password has to be set!", "Edit Entry Error", MessageBoxButtons.OK);
                return;
            }

            if (string.IsNullOrEmpty(txtBoxRepeat.Text))
            {
                MessageBox.Show("Please repeat your Password!", "Edit Entry Error", MessageBoxButtons.OK);
                return;
            }

            if (!string.Equals(txtBoxPassword.Text, txtBoxRepeat.Text))
            {
                MessageBox.Show("Repeated Password is not equal entered Password!", "Edit Entry Error", MessageBoxButtons.OK);
                return;
            }

            if (userCredential != null)
            {
                userDataDictionary.Add(Credential.UserDataType.Id, userCredential.GetData(Credential.UserDataType.Id));
            }

            userDataDictionary.Add(Credential.UserDataType.Title, txtBoxTitle.Text);
            userDataDictionary.Add(Credential.UserDataType.Email, txtBoxPrimary.Text);
            userDataDictionary.Add(Credential.UserDataType.Website, txtBoxWebsite.Text);
            userDataDictionary.Add(Credential.UserDataType.Password, txtBoxPassword.Text);

            userCredential = new Credential(userDataDictionary);

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Example #2
0
        public void EditButton_OnMouseClick(object sender, MouseEventArgs e)
        {
            Panel           panel           = (Panel)((Button)sender).Parent;
            GUIEntryCreator guiEntryCreator = userPasswordDictionary.Keys.First(x => x.entryPanel == panel);

            EditEntryDialog editEntryDialog = new EditEntryDialog();

            editEntryDialog.UserCredential = userPasswordDictionary[guiEntryCreator];

            if (editEntryDialog.ShowDialog() == DialogResult.OK)
            {
                Credential credential = new Credential(editEntryDialog.UserCredential);
                userPasswordDictionary.Remove(guiEntryCreator);

                entryFlowLayoutPanel.Controls.Remove(guiEntryCreator.entryPanel);

                userPasswordDictionary.Add(new GUIEntryCreator(
                                               entryFlowLayoutPanel,
                                               credential,
                                               new MouseEventHandler(DeleteButton_OnMouseClick),
                                               new MouseEventHandler(EditButton_OnMouseClick)), credential);

                int    entryId = int.Parse(credential.GetData(Credential.UserDataType.Id));
                byte[] command = new byte[180];
                command[0] = (byte)SerialCommandLimiter.COMM_BEGIN;
                command[1] = (byte)SerialCommand.COMM_EDIT_ACC;
                command[2] = (byte)((entryId & 0xFF00) >> 8);
                command[3] = (byte)(entryId & 0xFF);
                command[4] = (byte)SerialCommandLimiter.US;

                int commandIdx = 5;
                CopyArray(credential.GetData(Credential.UserDataType.Title), ref command, ref commandIdx, 16);
                command[commandIdx++] = (byte)SerialCommandLimiter.US;
                CopyArray(credential.GetData(Credential.UserDataType.Username), ref command, ref commandIdx, 32);
                command[commandIdx++] = (byte)SerialCommandLimiter.US;
                CopyArray(credential.GetData(Credential.UserDataType.Email), ref command, ref commandIdx, 64);
                command[commandIdx++] = (byte)SerialCommandLimiter.US;
                CopyArray(credential.GetData(Credential.UserDataType.Password), ref command, ref commandIdx, 32);
                command[commandIdx++] = (byte)SerialCommandLimiter.US;
                CopyArray(credential.GetData(Credential.UserDataType.Website), ref command, ref commandIdx, 24);
                command[commandIdx++] = (byte)SerialCommandLimiter.COMM_END;

                SerialSafeWrite(command, commandIdx);
            }
        }
Example #3
0
        private void onSerialDataRecieve(object sender, SerialDataReceivedEventArgs args)
        {
            string strData = serialPort.ReadExisting();

            byte[] byteData;
            try
            {
                byteData = Convert.FromBase64String(strData);
            }
            catch (FormatException ex)
            {
                return;
            }

            if (byteData.Length == 0)
            {
                return;
            }

            if (byteData[0] == (byte)SerialCommandLimiter.ACK && credentialQueue.Count != 0)
            {
                byte[] command =
                {
                    (byte)SerialCommandLimiter.COMM_BEGIN,
                    (byte)SerialCommand.COMM_GET_UNIQUE_ID,
                    (byte)SerialCommandLimiter.COMM_END
                };
                SerialSafeWrite(command, 3);
            }


            if (byteData[0] == (byte)SerialCommandLimiter.NACK)
            {
                MessageBox.Show("Something went wrong while communicating with the device!", "Device Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (byteData.Length < 4)
            {
                return;
            }

            if (!isValidCommand(byteData))
            {
                MessageBox.Show("Recieved an invalid command!", "Invalid Command", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            int entryId;

            switch ((SerialCommand)byteData[1])
            {
            case SerialCommand.COMM_SEND_ACC:
                entryId  = (byteData[2] << 8) | byteData[3];
                byteData = byteData.Skip(4).ToArray();

                string title = extractEntryData(ref byteData, (byte)SerialCommandLimiter.US);
                string usr   = extractEntryData(ref byteData, (byte)SerialCommandLimiter.US);
                string email = extractEntryData(ref byteData, (byte)SerialCommandLimiter.US);
                string pwd   = extractEntryData(ref byteData, (byte)SerialCommandLimiter.US);
                string url   = extractEntryData(ref byteData, (byte)SerialCommandLimiter.COMM_END);

                this.Invoke(new Action <int, string, string, string, string, string>(AddEntryFromSerial), entryId, title, usr, email, pwd, url);

                byte[] cmd = { (byte)SerialCommandLimiter.ACK };
                SerialSafeWrite(cmd, 1);
                break;

            case SerialCommand.COMM_SEND_UNIQUE_ID:
                if (credentialQueue.Count != 0)
                {
                    Credential credential = credentialQueue.Dequeue();
                    entryId = (byteData[2] << 8) | byteData[3];
                    this.Invoke(
                        new Action <int, string, string, string, string, string>(SendEntryToSerial),
                        entryId,
                        credential.GetData(Credential.UserDataType.Title),
                        credential.GetData(Credential.UserDataType.Username),
                        credential.GetData(Credential.UserDataType.Email),
                        credential.GetData(Credential.UserDataType.Password),
                        credential.GetData(Credential.UserDataType.Website));
                }

                byte[] ack = { (byte)SerialCommandLimiter.ACK };
                SerialSafeWrite(ack, 1);
                break;
            }
        }
        /// <summary>
        /// Initialize all Controls and add them to the panel
        /// </summary>
        /// <param name="credentialInfo">Credential info</param>
        /// <param name="parentWidth">Width of parent panel</param>
        /// <param name="mouseDeleteEventHandler">Event Handler for delete button</param>
        /// <param name="mouseEditeventHandler">Event Handler for edit button</param>
        private void Initialize(Credential credentialInfo, int parentWidth, MouseEventHandler mouseDeleteEventHandler, MouseEventHandler mouseEditeventHandler)
        {
            // Entry Icon
            entryIcon          = new PictureBox();
            entryIcon.Size     = new Size(40, 40);
            entryIcon.Image    = KeylessGo_GUI.Properties.Resources.software_icon;
            entryIcon.SizeMode = PictureBoxSizeMode.Zoom;
            entryIcon.Location = new Point(20, 20);

            // Entry Title
            entryTitle          = new Label();
            entryTitle.Font     = new Font("Calibri", 14, FontStyle.Bold);
            entryTitle.Text     = credentialInfo.GetData(Credential.UserDataType.Title);
            entryTitle.Location = new Point(85, 20);

            // Entry Username
            entryUsername          = new Label();
            entryUsername.Font     = new Font("Calibri", 12, FontStyle.Regular);
            entryUsername.Text     = string.Format("Username: {0}", credentialInfo.GetData(Credential.UserDataType.Email));
            entryUsername.Location = new Point(260, 20);
            entryUsername.AutoSize = true;

            // Entry Password
            entryPassword      = new Label();
            entryPassword.Font = new Font("Calibri", 12, FontStyle.Regular);

            string passwordString = "Password: "******"*";
            }

            entryPassword.Text     = passwordString;
            entryPassword.Location = new Point(260, 40);
            entryPassword.AutoSize = true;

            // Entry Website Link
            string websiteLink = credentialInfo.GetData(Credential.UserDataType.Website);

            if (string.IsNullOrEmpty(websiteLink))
            {
                entryWebsite          = new LinkLabel();
                entryWebsite.Text     = websiteLink;
                entryWebsite.Font     = new Font("Calibri", 12, FontStyle.Regular);
                entryWebsite.Location = new Point(85, 40);
                entryWebsite.AutoSize = true;

                try
                {
                    entryIcon.LoadAsync(string.Format(@"https://{0}/favicon.ico", websiteLink));
                }
                catch (Exception ex)
                {
                }
            }

            // Edit Entry Button
            entryEdit           = new Button();
            entryEdit.Text      = "";
            entryEdit.Image     = KeylessGo_GUI.Properties.Resources.edit_entry_icon;
            entryEdit.Size      = new Size(40, 40);
            entryEdit.Location  = new Point(parentWidth - 107, 20);
            entryEdit.FlatStyle = FlatStyle.Flat;
            entryEdit.FlatAppearance.BorderSize = 0;
            entryEdit.MouseClick += mouseEditeventHandler;

            // Edit Delete Button
            entryDelete           = new Button();
            entryDelete.Text      = "";
            entryDelete.Image     = KeylessGo_GUI.Properties.Resources.delete_entry_icon;
            entryDelete.Size      = new Size(40, 40);
            entryDelete.Location  = new Point(parentWidth - 67, 20);
            entryDelete.FlatStyle = FlatStyle.Flat;
            entryDelete.FlatAppearance.BorderSize = 0;
            entryDelete.MouseClick += mouseDeleteEventHandler;

            // Add Controls
            entryPanel.Controls.Add(entryIcon);
            entryPanel.Controls.Add(entryTitle);
            entryPanel.Controls.Add(entryUsername);
            entryPanel.Controls.Add(entryPassword);
            entryPanel.Controls.Add(entryWebsite);
            entryPanel.Controls.Add(entryEdit);
            entryPanel.Controls.Add(entryDelete);
        }