Exemple #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);
        }
Exemple #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);
        }