Esempio n. 1
0
        private void ChangePinButton_Click(object sender, EventArgs e)
        {
            Control[] controlsToDisable = { ChangePasswordButton, ChangePinButton, LogOutButton, BackButton };
            FormUtilities.DisableControls(controlsToDisable);

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

            EmailManager.SendEmail(LoggedUser.Email, "changePin", LoggedUser.Login, verificationCode.ToString());

            VerificationCodeForm vcf = new VerificationCodeForm(VerificationCodeForm.Mode.ChangePin, verificationCode, controlsToDisable, LoggedUser.Login);

            vcf.Show();
        }
        private void RemindButton_Click(object sender, EventArgs e)
        {
            string login = LoginTextBox.Text;
            string email = EmailTextBox.Text;

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

            if (!Regex.IsMatch(email, "[^@]+@[^@]+\\.[^@]+"))
            {
                MessageBox.Show($"Invalid email.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                FormUtilities.ClearTextBoxes(EmailTextBox);
                return;
            }

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

            if (!DBManager.GetSingleValueWhere("Users", "Email", "Login", login).Equals(email))
            {
                MessageBox.Show($"Email \'{email}\' is not associated with user \'{login}\'.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                FormUtilities.ClearTextBoxes(EmailTextBox);
                return;
            }

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


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

            VerificationCodeForm vcf = new VerificationCodeForm(VerificationCodeForm.Mode.Reminder, verificationCode, DisabledControls, login, email, /*password*/ DBManager.GetSingleValueWhere("Users", "Password", "Login", login));

            vcf.Show();
            FormUtilities.DisableControls(DisabledControls);
        }
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);
        }