コード例 #1
0
        public void SendMailToAdmin(string mailDest, User utente, DateTime date)
        {
            MailAddress destinatario = new MailAddress(mailDest);
            MailMessage message      = new MailMessage(this.mittente, destinatario);

            string       filename = "temp" + utente.Codice.ToString() + ".bmp";
            MemoryStream stream   = new MemoryStream();

            utente.Img.Save(stream, ImageFormat.Bmp);
            stream.Position = 0;

            Attachment att = new Attachment(stream, new ContentType());

            att.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
            att.ContentDisposition.Inline          = true;
            att.ContentId             = "imgUser";
            att.ContentType.MediaType = "image/png";
            att.ContentType.Name      = filename;

            message.Subject    = "NOTICE FOR ADMINISTRATOR";
            message.IsBodyHtml = true;
            string aux = "<div>The User " + utente.Name + " " + utente.Surname + " with the following registration number: ";

            aux         += utente.Codice + "<br>has entered in the stable without facial recognition. Pay Attention and ";
            aux         += "alert security staff!!<br><br> Access occurred at " + date.ToLongTimeString();
            aux         += " on the " + date.ToShortDateString();
            aux         += "</div><br><br><img src=\"cid:" + att.ContentId + "\"/><br><br>";
            message.Body = aux;
            message.Attachments.Add(att);

            SmtpClient sc = new SmtpClient();

            sc.UseDefaultCredentials = false;
            sc.DeliveryMethod        = SmtpDeliveryMethod.Network;
            sc.Host      = "smtp." + this.hostType + ".com";
            sc.EnableSsl = true;
            DataEncript de = new DataEncript();

            sc.Credentials = new NetworkCredential(mittente.Address, de.DecryptString(this.password));
            sc.Port        = 587;
            sc.Send(message);
        }
コード例 #2
0
        private void ModSaveButton_Click(object sender, EventArgs e)
        {
            int a;

            if (!this.ChangeCheckBox.Checked && !this.ModAdminCheckBox.Checked)
            {
                MessageBox.Show("Almost one have to be checked!!", "NOTICE", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (this.PwdUTextBox.Text == "" || !Int32.TryParse(this.PwdUTextBox.Text, out a) ||
                this.PwdUTextBox.Text.Length < 6)
            {
                MessageBox.Show("Enter a valid username in the appropriate field!!", "NOTICE",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.PwdUTextBox.Clear();
                this.PwdUTextBox.Focus();
                return;
            }

            int codice = Convert.ToInt32(this.PwdUTextBox.Text);

            if (!this.db.VerifyUserExists(codice))
            {
                MessageBox.Show("The code you entered is not associated with any User!!", "INFORMATION",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.PwdUTextBox.Clear();
                this.PwdUTextBox.Focus();
                return;
            }

            User          u     = this.db.SelectSimpleUser(codice);
            Administrator admin = null;

            if (u == null)
            {
                admin = this.db.SelectAdministrator(codice);
            }

            if (admin == null && this.ModAdminCheckBox.Checked)
            {
                MessageBox.Show("The User " + codice.ToString() + " is not a administrator!!", "NOTICE",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.ModAdminCheckBox.Checked = false;
                return;
            }

            if (this.ChangeCheckBox.Checked)
            {
                if (this.OldPwdTextBox.Text == "" || this.OldPwdTextBox.Text.Length < 4)
                {
                    MessageBox.Show("Enter a valid Old PIN in the appropriate field!!\nThe code entered is too short (must be four characters) or\n" +
                                    "the field appears to be empty! ", "NOTICE", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.OldPwdTextBox.Clear();
                    this.OldPwdTextBox.Focus();
                    return;
                }

                if (this.NewPwdTextBox.Text == "" || this.NewPwdTextBox.Text.Length < 4)
                {
                    MessageBox.Show("Enter a valid New PIN in the appropriate field!!\nThe code entered is too short (must be four characters) or\n" +
                                    "the field appears to be empty! ", "NOTICE", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.NewPwdTextBox.Clear();
                    this.NewPwdTextBox.Focus();
                    return;
                }

                SHA1   shaM    = new SHA1Managed();
                byte[] pin     = Encoding.ASCII.GetBytes(this.OldPwdTextBox.Text);
                string hashPin = Encoding.ASCII.GetString(shaM.ComputeHash(pin));
                bool   errore  = false;

                if (u == null)
                {
                    if (hashPin == admin.Password)
                    {
                        errore = false;
                    }
                    else
                    {
                        errore = true;
                    }
                }
                else
                {
                    if (hashPin == u.Password)
                    {
                        errore = false;
                    }
                    else
                    {
                        errore = true;
                    }
                }

                if (errore)
                {
                    MessageBox.Show("The old PIN does not match what is saved on the database!!", "NOTICE",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.OldPwdTextBox.Clear();
                    this.OldPwdTextBox.Focus();
                    return;
                }

                this.db.ChangePIN(codice, hashPin);
            }

            if (this.ModAdminCheckBox.Checked)
            {
                if (this.OldMailPwdTextBox.Text == "" || this.NewMailPwdTextBox.Text == "")
                {
                    MessageBox.Show("You must specify the old Mail Password, or new Mail Password, or both!!", "NOTICE",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                DataEncript de = new DataEncript();

                if (this.OldMailPwdTextBox.Text != de.DecryptString(admin.MailPassword))
                {
                    this.db.ChangeMailPassword(codice, de.EncryptString(this.NewMailPwdTextBox.Text));
                }
                else
                {
                    MessageBox.Show("The old mail password does not match what is saved on the database!!", "NOTICE",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.OldMailPwdTextBox.Clear();
                    this.OldMailPwdTextBox.Focus();
                    return;
                }
            }

            MessageBox.Show("Passwords updated successfully!!", "NOTICE", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
コード例 #3
0
        private void InsertButton_Click(object sender, EventArgs e)
        {
            int  aux;
            bool errorInsert = false;

            if (this.NameTextBox.Text == "" && this.SurnameTextBox.Text == "" &&
                this.PasswordTextBox.Text == "" && UsernameTextBox.Text == "" && !this.PhotoCheckBox.Checked)
            {
                MessageBox.Show("Complete all fields before continuing, after having\ncompleted them " +
                                "click on the botton Insert!", "NOTICE", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.NameTextBox.Focus();
                return;
            }

            if (this.NameTextBox.Text == "")
            {
                MessageBox.Show("Complete the Name field before continuing!!", "NOTICE",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.NameTextBox.Focus();
                return;
            }

            if (this.SurnameTextBox.Text == "")
            {
                MessageBox.Show("Complete the Surname field before continuing!!", "NOTICE",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.SurnameTextBox.Focus();
                return;
            }

            if (this.UsernameTextBox.Text == "" || !Int32.TryParse(this.UsernameTextBox.Text, out aux) &&
                this.UsernameTextBox.Text.Length < 6)
            {
                MessageBox.Show("Enter a valid username in the appropriate field!!", "NOTICE",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.UsernameTextBox.Clear();
                this.UsernameTextBox.Focus();
                return;
            }

            if (this.PasswordTextBox.Text == "" || !Int32.TryParse(this.PasswordTextBox.Text, out aux) &&
                this.UsernameTextBox.Text.Length < 4)
            {
                MessageBox.Show("Enter a valid password in the appropriate field!!", "NOTICE",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.PasswordTextBox.Clear();
                this.UsernameTextBox.Focus();
                return;
            }

            if (this.db.VerifyUserExists(Convert.ToInt32(this.UsernameTextBox.Text)))
            {
                MessageBox.Show("Already exists in the system, a user with this username code!!", "NOTICE",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            if (!this.PhotoCheckBox.Checked)
            {
                MessageBox.Show("Select your own pictures before proceeding", "NOTICE",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            SHA1 shaM   = new SHA1Managed();
            char gender = Convert.ToChar(this.GenderComboBox.Text);

            byte[] pass  = Encoding.ASCII.GetBytes(this.PasswordTextBox.Text);
            string hash1 = Encoding.ASCII.GetString(shaM.ComputeHash(pass));

            if (this.AdminCheckBox.Checked)
            {
                if (this.MailPwdTextBox.Text == "" && this.MailTextBox.Text == "")
                {
                    MessageBox.Show("Enter the credentials of the email account of the administrator!!", "NOTICE",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.MailTextBox.Focus();
                    return;
                }

                if (this.MailTextBox.Text == "" || !MailManagement.VerificaCorrettezzaMail(this.MailTextBox.Text))
                {
                    MessageBox.Show("Enter the correct Mail address of the Administrator!!", "NOTICE", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.MailTextBox.Focus();
                    return;
                }

                if (this.MailPwdTextBox.Text == "")
                {
                    MessageBox.Show("Enter tha password associated with the mail of the administrator!!", "NOTICE",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.MailPwdTextBox.Focus();
                    return;
                }

                DataEncript   de    = new DataEncript();
                Administrator admin = new Administrator(Convert.ToInt32(this.UsernameTextBox.Text), hash1, gender,
                                                        this.dateTimePicker1.Value, this.NameTextBox.Text, this.SurnameTextBox.Text, this.MailTextBox.Text,
                                                        de.EncryptString(this.MailPwdTextBox.Text), this.PhotoPictureBox.BackgroundImage);

                try {
                    this.db.InsertAdministrator(admin);
                    this.db.InsertImage(admin.Codice, this.grayFace.Bytes);
                    this.MailPwdTextBox.Clear();
                    this.MailTextBox.Clear();
                    this.AdminCheckBox.Checked = false;
                } catch (DatabaseException dbEx) {
                    errorInsert = true;
                    MessageBox.Show(dbEx.Mex, "ANOMALY", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                User u = new User(Convert.ToInt32(this.UsernameTextBox.Text), hash1, gender, this.dateTimePicker1.Value,
                                  this.NameTextBox.Text, this.SurnameTextBox.Text, this.PhotoPictureBox.BackgroundImage);

                try {
                    this.db.InsertSimpleUser(u);
                    this.db.InsertImage(u.Codice, this.grayFace.Bytes);
                } catch (DatabaseException dbEx) {
                    errorInsert = true;
                    MessageBox.Show(dbEx.Mex, "ANOMALY", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            if (!errorInsert)
            {
                MessageBox.Show("The User has been properly registered!!", "SUCCESS",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);

                this.UsernameTextBox.Clear();
                this.SurnameTextBox.Clear();
                this.PhotoPictureBox.BackgroundImage = null;
                this.dateTimePicker1.Value           = this.dateTimePicker1.MaxDate;
                this.GenderComboBox.Text             = "F";
                this.NameTextBox.Clear();
                this.PasswordTextBox.Clear();
                this.PhotoCheckBox.Checked = false;
                this.UsernameTextBox.Focus();
            }
        }