private void bt_chngPasswd_Click(object sender, EventArgs e)
        {
            bool pass_valide     = false;
            bool new_pass_valide = false;

            if (txtbox_oldPasswd.Text == user.Passwd)
            {
                pass_valide = true;
            }
            else
            {
                MsgBox msgBox = new MsgBox("Bad passwords", "The old password was entered incorrectly.");
                msgBox.ShowDialog();
            }
            if (txtBox_newPasswd.Text.Length >= 5 && txtBox_newPasswd.Text == txtBox_confirmNewPasswd.Text)
            {
                new_pass_valide = true;
            }
            else
            {
                MsgBox msgBox = new MsgBox("Bad passwords", "Password must be at least 5 characters long. The passwords entered must match.");
                msgBox.ShowDialog();
            }
            if (new_pass_valide && pass_valide)
            {
                user.ChangePasswd(txtBox_newPasswd.Text);
                user.Serialize();
                MsgBox msgBox = new MsgBox("Changing password", "Password changed successfully");
                msgBox.ShowDialog();
                Desktop.BringToFront();
                this.Close();
            }
        }
Exemple #2
0
        private void bt_chngEmail_Click(object sender, EventArgs e)
        {
            bool email_valide = false;

            if (txtbox_Passwd.Text == user.Passwd)
            {
                List <string> emails = new List <string>();
                using (var reader = new StreamReader("emails/emails"))
                {
                    while (!reader.EndOfStream)
                    {
                        emails.Add(reader.ReadLine());
                    }
                }
                var email_reg = new Regex(@"^[a-z,A-Z,0-9](\.?[a-z,A-Z,0-9]){5,}@[a-z]{2,}\.(com|net|ua|ru)$");
                if (email_reg.IsMatch(txtBox_newEmail.Text))
                {
                    email_valide = true;
                }
                else
                {
                    MsgBox msgBox = new MsgBox("Bad email", "Invalid email specified.");
                    msgBox.ShowDialog();
                }
                if (email_valide && emails.Contains(txtBox_newEmail.Text))
                {
                    email_valide = false;
                    MsgBox msgBox = new MsgBox("Bad email", "A user with this email already exists!");
                    msgBox.ShowDialog();
                }
                if (email_valide)
                {
                    emails.Remove(user.Email);
                    user.ChangeEmail(txtBox_newEmail.Text);
                    user.Serialize();
                    emails.Add(txtBox_newEmail.Text);
                    using (var writer = new StreamWriter("emails/emails"))
                    {
                        foreach (var email in emails)
                        {
                            writer.WriteLine(email.ToString());
                        }
                    }
                    MsgBox msgBox = new MsgBox("Changing email", "Email changed successfully");
                    msgBox.ShowDialog();
                    Desktop.BringToFront();
                    this.Close();
                }
            }
            else
            {
                MsgBox msgBox = new MsgBox("Bad passwords", "The password was entered incorrectly.");
                msgBox.ShowDialog();
            }
        }