Пример #1
0
        private void girisButtonPressed(object sender, EventArgs e)
        {
            if (adminForm == null)
            {
                if (!File.Exists("tempfiles.xml")) // ilk açılışta veya bir sıkıntı sonucu kategoriler dosyası silinirse kendi default kategorilerimizi giriyoruz.
                {
                    infoKullanici = new UItemp[1];

                    infoKullanici[0] = new UItemp();
                    infoKullanici[0].UIN = (new UnicodeEncoding()).GetBytes("Adınız");
                    infoKullanici[0].UIS = (new UnicodeEncoding()).GetBytes("Soy Adınız");
                    infoKullanici[0].UIUN = (new UnicodeEncoding()).GetBytes("admin");
                    infoKullanici[0].UIU = (new UnicodeEncoding()).GetBytes("Yönetici");

                    infoKullanici[0].UIPN = PasswordHash.CreateHash("0000");
                    infoKullanici[0].UIPW = PasswordHash.CreateHash("00000");
                    infoKullanici[0].UIY[0] = PasswordHash.CreateHash("true");
                    infoKullanici[0].UIY[1] = PasswordHash.CreateHash("true");
                    infoKullanici[0].UIY[2] = PasswordHash.CreateHash("true");
                    infoKullanici[0].UIY[3] = PasswordHash.CreateHash("true");
                    infoKullanici[0].UIY[4] = PasswordHash.CreateHash("true");

                    XmlSave.SaveRestoran(infoKullanici, "tempfiles.xml");

                    File.SetAttributes("tempfiles.xml", FileAttributes.Archive);
                }
                XmlLoad<UItemp> loadInfoKullanicilar = new XmlLoad<UItemp>();
                infoKullanici = loadInfoKullanicilar.LoadRestoran("tempfiles.xml");

                string[] username = new string[1];
                username[0] = userNameTextBox.getNameText(); //name lazım olduğunda al
                string password = passwordTextBox.getPasswordText(); //password lazım olduğunda al

                int kullaniciAdi = -5;

                if (username[0] == "ropisimiz" && password == "roproprop")
                {
                    XmlSave.SaveRestoran(username, "sonKullanici.xml");

                    try
                    {
                        Task reportTask = Task.Factory.StartNew(
                            () =>
                            {
                                adminForm = new AdminGirisFormu(this, true);
                                adminForm.ShowDialog();
                            }
                            , CancellationToken.None
                            , TaskCreationOptions.None
                            , TaskScheduler.FromCurrentSynchronizationContext()
                            );

                        reportTask.Wait();
                    }
                    catch
                    { }

                    //Task.Factory.StartNew(() => adminForm.ShowDialog());
                    //adminForm.Show();
                }
                else
                {
                    for (int i = 0; i < infoKullanici.Count(); i++)
                    {
                        if (username[0] == (new UnicodeEncoding()).GetString(infoKullanici[i].UIUN))
                        {
                            kullaniciAdi = i;
                            break;
                        }
                    }
                    if (kullaniciAdi != -5)
                    {
                        //bool flag = Helper.VerifyHash(password, "SHA512", infoKullanici[kullaniciAdi].UIPW);

                        bool flag = PasswordHash.ValidatePassword(password, infoKullanici[kullaniciAdi].UIPW);

                        bool adisyonDegistirebilirMi = false;

                        if (PasswordHash.ValidatePassword("true", infoKullanici[kullaniciAdi].UIY[3]))
                            adisyonDegistirebilirMi = true;

                        if (flag == true)
                        { //şifre doğru
                            XmlSave.SaveRestoran(username, "sonKullanici.xml");

                            try
                            {
                                Task reportTask = Task.Factory.StartNew(
                                    () =>
                                    {
                                        adminForm = new AdminGirisFormu(this, adisyonDegistirebilirMi);

                                        adminForm.ShowDialog();
                                    }
                                    , CancellationToken.None
                                    , TaskCreationOptions.None
                                    , TaskScheduler.FromCurrentSynchronizationContext()
                                    );

                                reportTask.Wait();
                            }
                            catch
                            { }
                            //Task.Factory.StartNew(() => adminForm.ShowDialog());
                        }
                        else
                        {
                            KontrolFormu dialog2 = new KontrolFormu("Yanlış kullanıcı adı/şifre girdiniz", false);
                            dialog2.Show();
                        }
                    }
                    else
                    {
                        KontrolFormu dialog2 = new KontrolFormu("Yanlış kullanıcı adı/şifre girdiniz", false);
                        dialog2.Show();
                    }
                }

                userNameTextBox = new WPF_UserControls.VerticalCenterTextBox();
                usernameBoxHost.Child = userNameTextBox;
                passwordTextBox = new WPF_UserControls.VerticalCenterPasswordBox();
                passwordBoxHost.Child = passwordTextBox;
            }
            else
            {
                this.SendToBack();
            }
        }
Пример #2
0
        //yeni kullanıcı ekle veya kullanıcıyı güncelle butonu
        private void buttonSaveNewUserPressed(object sender, EventArgs e)
        {
            KontrolFormu dialog;
            if (textboxUserName.Text == "Yeni Kullanıcı" || textboxUserName.Text == "" || textboxSurname.Text == "" || textboxName.Text == "")
            {
                dialog = new KontrolFormu("Eksik veya hatalı bilgi girdiniz, lütfen kontrol ediniz", false);
                dialog.Show();

                return;
            }

            if (newUserForm.Text == "Yeni Kullanıcı")
            {// yeni Kullanıcı kaydetme
                if (textboxPin.Text == "" || textBoxPassword.Text == "")
                {
                    dialog = new KontrolFormu("Pin/Şifre girmediniz, lütfen kontrol edin", false);
                    dialog.Show();
                    return;
                }

                for (int j = 0; j < kullaniciListesi.Count(); j++)
                {
                    if (textboxUserName.Text == (new UnicodeEncoding()).GetString(kullaniciListesi[j].UIUN))
                    {
                        dialog = new KontrolFormu("Kullanımda olan bir kullanıcı adı girdiniz, lütfen kontrol edin", false);
                        dialog.Show();
                        return;
                    }
                    //else if (Helper.VerifyHash(textboxPin.Text, "SHA512", kullaniciListesi[j].UIPN))
                    else if (PasswordHash.ValidatePassword(textboxPin.Text, kullaniciListesi[j].UIPN))
                    {
                        dialog = new KontrolFormu("Kullanımda olan bir pin girdiniz, lütfen kontrol edin", false);
                        dialog.Show();
                        return;
                    }
                }

                // tüm Kullanıcılar görünümüne kategoriyi ekliyoruz
                treeUserName.Nodes.Add(textboxName.Text + " " + textboxSurname.Text);

                newUserForm.Text = textboxUserName.Text;

                // tüm Kullanıcılar listemize Kullanıcıyı ekleyip kaydediyoruz
                UItemp temp = new UItemp();
                temp.UIN = (new UnicodeEncoding()).GetBytes(textboxName.Text);
                temp.UIS = (new UnicodeEncoding()).GetBytes(textboxSurname.Text);
                temp.UIUN = (new UnicodeEncoding()).GetBytes(textboxUserName.Text);
                temp.UIU = (new UnicodeEncoding()).GetBytes(comboNewTitle.Text);

                /*
                temp.UIPN = Helper.ComputeHash(textboxPin.Text, "SHA512", null);
                temp.UIPW = Helper.ComputeHash(textBoxPassword.Text, "SHA512", null);

                for (int i = 0; i < 5; i++)
                {
                    if (treeYetkiler.Nodes[i].Checked)
                        temp.UIY[i] = Helper.ComputeHash("true", "SHA512", null);
                    else
                        temp.UIY[i] = Helper.ComputeHash("false", "SHA512", null);
                }
                */

                temp.UIPN = PasswordHash.CreateHash(textboxPin.Text);
                temp.UIPW = PasswordHash.CreateHash(textBoxPassword.Text);

                for (int i = 0; i < 5; i++)
                {
                    if (treeYetkiler.Nodes[i].Checked)
                        temp.UIY[i] = PasswordHash.CreateHash("true");
                    else
                        temp.UIY[i] = PasswordHash.CreateHash("false");
                }

                kullaniciListesi.Add(temp);

                // dosya korumayı açıyoruz
                File.SetAttributes("tempfiles.xml", FileAttributes.Normal);

                //kaydediyoruz
                XmlSave.SaveRestoran(kullaniciListesi, "tempfiles.xml");

                //yeniden korumaları ekliyoruz
                File.SetAttributes("tempfiles.xml", FileAttributes.Archive);

                treeUserName.SelectedNode = treeUserName.Nodes[treeUserName.Nodes.Count - 1];
                treeUserName.Focus();

                buttonDeleteUser.Visible = true;
                buttonAddNewUser.Enabled = true;
                buttonCancel.Visible = false;

                dialog = new KontrolFormu("Yeni Kullanıcı Bilgileri Kaydedilmiştir", false);
                dialog.Show();
            }
            else // Kullanıcı düzenleme
            {
                if (textboxPin.Text != "")
                {
                    DialogResult eminMisiniz;

                    dialog = new KontrolFormu(treeUserName.SelectedNode.Text + " adlı kullanıcının pinini değiştirmek istediğinize emin misiniz?", true);
                    {
                        eminMisiniz = dialog.ShowDialog();
                    }

                    if (eminMisiniz == DialogResult.No)
                    {
                        textboxPin.Text = "";
                        return;
                    }
                }

                if (textBoxPassword.Text != "")
                {
                    DialogResult eminMisiniz;

                    dialog = new KontrolFormu(treeUserName.SelectedNode.Text + " adlı kullanıcının şifresini değiştirmek istediğinize emin misiniz?", true);

                    eminMisiniz = dialog.ShowDialog();

                    if (eminMisiniz == DialogResult.No)
                    {
                        textBoxPassword.Text = "";
                        return;
                    }
                }

                int kacTane = 0, kacTane1 = 0;

                for (int j = 0; j < kullaniciListesi.Count(); j++)
                {
                    //if (Helper.VerifyHash(textboxPin.Text, "SHA512", kullaniciListesi[j].UIPN))
                    if (PasswordHash.ValidatePassword(textboxPin.Text, kullaniciListesi[j].UIPN))
                    {
                        kacTane++;
                    }
                    if (textboxUserName.Text == (new UnicodeEncoding()).GetString(kullaniciListesi[j].UIUN))
                        kacTane1++;

                    if (kacTane == 2 || kacTane1 == 2)
                    {
                        dialog = new KontrolFormu("Hatalı kullanıcı adı veya pin girdiniz, lütfen kontrol edin", false);
                        dialog.Show();
                        return;
                    }
                }

                int i = treeUserName.SelectedNode.Index;
                //kullanıcının listedeki bilgilerini güncelliyoruz ve kaydediyoruz
                kullaniciListesi[i].UIUN = (new UnicodeEncoding()).GetBytes(textboxUserName.Text);
                kullaniciListesi[i].UIN = (new UnicodeEncoding()).GetBytes(textboxName.Text);
                kullaniciListesi[i].UIS = (new UnicodeEncoding()).GetBytes(textboxSurname.Text);
                kullaniciListesi[i].UIUN = (new UnicodeEncoding()).GetBytes(textboxUserName.Text);

                kullaniciListesi[i].UIU = (new UnicodeEncoding()).GetBytes(comboNewTitle.Text);

                if (textboxPin.Text != "")
                    kullaniciListesi[i].UIPN = PasswordHash.CreateHash(textboxPin.Text);

                if (textBoxPassword.Text != "")
                    kullaniciListesi[i].UIPW = PasswordHash.CreateHash(textBoxPassword.Text);

                for (int x = 0; x < 5; x++)
                {
                    if (treeYetkiler.Nodes[x].Checked)
                        kullaniciListesi[i].UIY[x] = PasswordHash.CreateHash("true");
                    else
                        kullaniciListesi[i].UIY[x] = PasswordHash.CreateHash("false");
                }

                // dosya korumayı açıyoruz
                File.SetAttributes("tempfiles.xml", FileAttributes.Normal);

                //kaydediyoruz
                XmlSave.SaveRestoran(kullaniciListesi, "tempfiles.xml");

                //yeniden korumaları ekliyoruz
                File.SetAttributes("tempfiles.xml", FileAttributes.Archive);

                //görünümdeki isimleri güncelliyoruz
                treeUserName.SelectedNode.Text = textboxName.Text + " " + textboxSurname.Text;
                newUserForm.Text = textboxUserName.Text;
                dialog = new KontrolFormu("Kullanıcı Bilgileri Güncellenmiştir", false);
                dialog.Show();
            }
        }