Esempio n. 1
0
        private void LogInButton_Click(object sender, EventArgs e)
        {
            string login    = LoginTextBox.Text;
            string password = PasswordTextBox.Text;

            if (login.Equals("") || password.Equals(""))
            {
                MessageBox.Show("All fields are required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (!DBManager.GetColumnValues("Users", "Login").Contains(login))
            {
                MessageBox.Show($"Invalid user \'{login}\'.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                FormUtilities.ClearTextBoxes(LoginTextBox, PasswordTextBox);
                return;
            }

            if (!DBManager.GetSingleValueWhere("Users", "Password", "Login", login).Equals(password))
            {
                MessageBox.Show("Invalid password.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                FormUtilities.ClearTextBoxes(PasswordTextBox);
                return;
            }

            User loggedUser = new User(login, DBManager.GetSingleValueWhere("Users", "Email", "Login", login),
                                       password, DBManager.GetSingleValueWhere("Users", "Pin", "Login", login));

            loggedUser.Id = Convert.ToInt32(DBManager.GetSingleValueWhere("Users", "Id", "Login", login));

            EmailManager.SendEmail(loggedUser.Email, "alert", loggedUser.Login, DateTime.Now.ToString());

            FormUtilities.ClearTextBoxes(LoginTextBox, PasswordTextBox);
            this.Hide();
            MainForm mf = new MainForm(this, loggedUser);

            mf.Show();
        }
        private void VerifyButton_Click(object sender, EventArgs e)
        {
            string enteredCode = CodeTextBox.Text;

            if (enteredCode.Equals(VerificationCode.ToString()))
            {
                switch (_Mode)
                {
                case Mode.Register:
                    DBManager.AddUser(_User.Login, _User.Email, _User.Password, _User.Pin);
                    this.Close();
                    MessageBox.Show($"User \'{_User.Login}\' has been created.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;

                case Mode.Reminder:
                    EmailManager.SendEmail(_User.Email, "reminder", _User.Password);
                    this.Close();
                    MessageBox.Show("Your password has been sent to your email address.", "Success", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    break;

                case Mode.ChangePassword:
                    this.Close();
                    ChangePasswordForm cpf = new ChangePasswordForm(_User, DisabledControls);
                    cpf.Show();
                    break;

                case Mode.ChangePin:
                    this.Close();
                    ChangePinForm _cpf = new ChangePinForm(_User, DisabledControls);
                    _cpf.Show();
                    break;

                case Mode.Export:
                    this.Close();
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.ShowDialog();

                    string path = sfd.FileName;

                    List <string> titles = DBManager.GetColumnValuesWhere("Accounts", "Title", "UserId", DBManager.GetSingleValueWhere("Users", "Id", "Login", _User.Login).ToString());

                    List <string> logins = DBManager.GetColumnValuesWhere("Accounts", "Login", "UserId", DBManager.GetSingleValueWhere("Users", "Id", "Login", _User.Login).ToString());

                    List <string> emails = DBManager.GetColumnValuesWhere("Accounts", "Associated_Email", "UserId", DBManager.GetSingleValueWhere("Users", "Id", "Login", _User.Login).ToString());

                    List <string> passwords = DBManager.GetColumnValuesWhere("Accounts", "Password", "UserId", DBManager.GetSingleValueWhere("Users", "Id", "Login", _User.Login).ToString());

                    try
                    {
                        using (StreamWriter sw = new StreamWriter(path))
                        {
                            for (int i = 0; i < titles.Count; i++)
                            {
                                string accountRowForFile = "Title: " + titles[i] + "\tLogin: "******"\tAssociated email: " +
                                                           emails[i] + "\tPassword: "******"Your data has been successfully exported.\n\nWarning: The exported file contains all of your accounts data. Be cautious when granting access to this file. Deleting the file\nfrom widely accessible disk space is recommended.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Export has been cancelled.", "Export cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    break;
                }
            }
            else
            {
                FormUtilities.ClearTextBoxes(CodeTextBox);
                MessageBox.Show("Invalid verification code.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 3
0
        private void RegisterButton_Click(object sender, EventArgs e)
        {
            string login    = LoginTextBox.Text;
            string email    = EmailTextBox.Text;
            string password = PasswordTextBox.Text;
            string confirm  = ConfirmTextBox.Text;
            string pin      = PinTextBox.Text;

            /* CHECK IF ALL FIELDS HAS INPUT*/
            if (new string[] { login, email, password, confirm, pin }.Contains(""))
            {
                MessageBox.Show("All fields are required.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                FormUtilities.ClearTextBoxes(PasswordTextBox, ConfirmTextBox, PinTextBox);
                return;
            }

            /* CHECK IF LOGIN IS AVAILABLE */
            if (DBManager.GetColumnValues("Users", "Login").Contains(login))
            {
                MessageBox.Show($"Login \'{login}\' is already used.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                FormUtilities.ClearTextBoxes(LoginTextBox, PasswordTextBox, ConfirmTextBox, PinTextBox);
                return;
            }

            /* CHECK EMAIL FORMAT */
            if (!Regex.IsMatch(email, "[^@]+@[^@]+\\.[^@]+"))
            {
                MessageBox.Show($"Invalid email.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                FormUtilities.ClearTextBoxes(EmailTextBox, PasswordTextBox, ConfirmTextBox, PinTextBox);
                return;
            }

            /* CHECK PASSWORD LENGTH */
            if (password.Length < 8)
            {
                MessageBox.Show($"Password must be at least 8 characters long.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                FormUtilities.ClearTextBoxes(PasswordTextBox, ConfirmTextBox, PinTextBox);
                return;
            }

            /* CHECK PASSWORD CONFIRMATION */
            if (!password.Equals(confirm))
            {
                MessageBox.Show("Password and password confirmation do not match.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                FormUtilities.ClearTextBoxes(PasswordTextBox, ConfirmTextBox, PinTextBox);
                return;
            }



            int verificationCode = new Random().Next(100000, 999999);


            EmailManager.SendEmail(email, "greeting", login, verificationCode.ToString());
            this.Close();

            VerificationCodeForm vcf = new VerificationCodeForm(VerificationCodeForm.Mode.Register, verificationCode, DisabledControls, login, email, password, pin);

            vcf.Show();
            FormUtilities.DisableControls(DisabledControls);
        }