示例#1
0
        private void btnRReg_Click(object sender, EventArgs e)
        {
            foreach (oneUser DB in Program.myList)
            {
                if (DB.username == txtRUser.Text) // проверка, есть ли пользователь
                {
                    MessageBox.Show("Already existing user.");
                    return;
                }
            }

            bool passCheck = CheckPasswordRules(txtRPassword.Text); // проверка пароля на символы

            if (passCheck)
            {
                MessageBox.Show("Please don't use same symbols!");
                return;
            }

            if (txtRPassword.Text != txtRRPassword.Text) // проверка пароля на совпадения
            {
                MessageBox.Show("Passes not the same");
                return;
            }
            oneUser ddbb = new oneUser();

            ddbb.username = txtRUser.Text;
            ddbb.password = txtRPassword.Text;
            ddbb.name     = txtName.Text;
            ddbb.surname  = txtSurName.Text;
            ddbb.city     = txtCity.Text;
            ddbb.status   = "user";
            ddbb.block    = "no";
            Program.myList.Add(ddbb);
            try
            {
                StreamWriter sw = new StreamWriter("DB_Decrypt.txt");
                sw.WriteLine(Program.myList.Count);
                for (int i = 0; i < Program.myList.Count; i++)
                {
                    sw.WriteLine(Program.myList[i].username + "," + Program.myList[i].password + "," +
                                 Program.myList[i].name + "," + Program.myList[i].surname + "," + Program.myList[i].city + "," +
                                 Program.myList[i].status + "," + Program.myList[i].block + ",");
                }
                sw.Close();
            }
            catch { MessageBox.Show("Ошибка сохранения настроек"); }
            MessageBox.Show("Data Export");
            this.Hide();
            form.Show();
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            foreach (oneUser DB in Program.myList) //проверка, есть ли пользователь в базе
            {
                if (DB.username == txtUserNameNew.Text)
                {
                    MessageBox.Show("Already existing user");
                    txtUserNameNew.Text = null;
                    return;
                }
            }

            oneUser newUser = new oneUser(); //если все окей, добавляем пустого пользователя

            newUser.username = txtUserNameNew.Text;
            newUser.password = "";
            newUser.name     = "";
            newUser.surname  = "";
            newUser.city     = "";
            newUser.status   = "user";
            newUser.block    = "no";
            Program.myList.Add(newUser);
            try
            {
                StreamWriter sw = new StreamWriter("DB_Decrypt.txt"); //перезаписываем файл с новым пользователем
                sw.WriteLine(Program.myList.Count);
                for (int i = 0; i < Program.myList.Count; i++)
                {
                    sw.WriteLine(Program.myList[i].username + "," + Program.myList[i].password + "," +
                                 Program.myList[i].name + "," + Program.myList[i].surname + "," + Program.myList[i].city + "," +
                                 Program.myList[i].status + "," + Program.myList[i].block + ",");
                }
                sw.Close();
            }
            catch { MessageBox.Show("Ошибка сохранения настроек"); }
            MessageBox.Show("Data Export");
            txtUserNameNew.Text = null;
        }
示例#3
0
        /*
         * private static bool Signatura()
         * {
         *  MD5 md5 = new MD5CryptoServiceProvider();
         *  //Signature
         *  string Signature = SystemInformation.UserName + SystemInformation.UserDomainName +
         *      Environment.GetEnvironmentVariable("windir") + Environment.SystemDirectory.ToString() +
         *          Convert.ToString(SystemInformation.MouseButtons) + SystemInformation.WorkingArea.Width.ToString();
         *
         *  byte[] signature = md5.ComputeHash(Encoding.UTF8.GetBytes(Signature));
         *  string signatureReg = BitConverter.ToString(signature).Replace("-", String.Empty);
         *
         *  string sigReg;
         *  RegistryKey readKey = Registry.CurrentUser.OpenSubKey("Sydorchuk");
         *  sigReg = readKey.GetValue("Signature").ToString();
         *
         *  if (signatureReg != sigReg)
         *      return false;
         *  else
         *      return true;
         * }
         */
        private void Form1_Load(object sender, EventArgs e)
        {
            MessageBox.Show("Добро пожаловать в программу Login Form!");
            /* If file not exists, create encrypt file with data about 'admin' */
            if (!File.Exists("DB_Encrypt.txt"))
            {
                Crypt.AddToReg();
                StreamWriter sw = new StreamWriter("DB_Encrypt.txt");
                sw.WriteLine(Crypt.Encrypt("1"));
                sw.WriteLine(Crypt.Encrypt("admin,,Vlad,Sydorchuk,Kyiv,admin,no,"));
                sw.Close();
            }

            /* Create StreamReader and reading info from DB_Encrypt and then write
             * it to temporary file DB_Decrypt */
            StreamReader sr  = new StreamReader("DB_Encrypt.txt");
            StreamWriter sw1 = new StreamWriter("DB_Decrypt.txt");
            int          n   = Convert.ToInt32(Crypt.Decrypt(sr.ReadLine()));

            sw1.WriteLine(n);
            for (int i = 0; i < n; i++)
            {
                sw1.WriteLine(Crypt.Decrypt(sr.ReadLine()));
            }
            sw1.Close();
            sr.Close();

            /* Write info from file to Program.myList */
            StreamReader sr1 = new StreamReader("DB_Decrypt.txt");
            int          n1  = Convert.ToInt32(sr1.ReadLine());

            try
            {
                for (int i = 0; i < n1; i++)
                {
                    oneUser ddbb = new oneUser();
                    String  Line = sr1.ReadLine();
                    int     sep  = Line.IndexOf(",");
                    ddbb.username = Line.Substring(0, sep);
                    Line          = Line.Substring(sep + 1);
                    sep           = Line.IndexOf(",");
                    ddbb.password = Line.Substring(0, sep);
                    Line          = Line.Substring(sep + 1);
                    sep           = Line.IndexOf(",");
                    ddbb.name     = Line.Substring(0, sep);
                    Line          = Line.Substring(sep + 1);
                    sep           = Line.IndexOf(",");
                    ddbb.surname  = Line.Substring(0, sep);
                    Line          = Line.Substring(sep + 1);
                    sep           = Line.IndexOf(",");
                    ddbb.city     = Line.Substring(0, sep);
                    Line          = Line.Substring(sep + 1);
                    sep           = Line.IndexOf(",");
                    ddbb.status   = Line.Substring(0, sep);
                    Line          = Line.Substring(sep + 1);
                    sep           = Line.IndexOf(",");
                    ddbb.block    = Line.Substring(0, sep);
                    Program.myList.Add(ddbb);
                }
            }
            catch { MessageBox.Show("File has problem"); }
            sr1.Close();
        }