Пример #1
0
        private void DisplayList(string filename, List <Accounts> list)
        {
            Accounts accounts   = new Accounts();
            String   path       = Directory.GetCurrentDirectory();                          //and the data in the list is written to the data file
            string   file       = filename + ".txt";
            string   pathString = Path.Combine(path, file);

            list.Clear();
            using (StreamReader SR = new StreamReader(pathString))              // StreamReader to read values from file
            {
                int    i      = 0;
                Logins logins = new Logins();
                String S      = SR.ReadLine();
                while (S != null)
                {
                    i++;
                    if (i == 1)
                    {
                        accounts.Type = S;
                    }
                    else if (i == 2)
                    {
                        accounts.Username = S;
                    }
                    else if (i == 3)
                    {
                        accounts.Password = S;
                        list.Add(new Accounts(accounts.Type, accounts.Username, accounts.Password));
                        i        = 0;
                        accounts = new Accounts();
                    }
                    S = SR.ReadLine();
                }
            }

            ResultListView.Clear();
            ResultListView.Columns.Add("Account", 120);
            ResultListView.Columns.Add("User ID", 230);
            for (int i = 0; i < list.Count; i++)
            {
                ListViewItem item1 = new ListViewItem(list[i].Type, 0);             //Add the list items into the view
                item1.SubItems.Add(list[i].Username);
                ResultListView.Items.AddRange(new ListViewItem[] { item1 });
            }
        }
Пример #2
0
        //Method for writing the new login values into the file
        private void WriteList(List <Logins> list, string Username, string Password)
        {
            Logins logins = new Logins();

            logins.Username = Username;
            logins.Password = Password;
            list.Add(new Logins(logins.Username, logins.Password));         //the new entry is added to the list
            String path = Directory.GetCurrentDirectory();                  //and the data in the list is

            //written to the data file
            using (TextWriter TW = new StreamWriter(path + "\\login.txt"))
            {                                                                               //Textwriter writes the values into the data file
                for (int k = 0; k < list.Count; k++)
                {
                    TW.WriteLine(loginsList[k].Username);
                    TW.WriteLine(loginsList[k].Password);
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            Passwords p = new Passwords();

            p.Password = tbPassword.Text;

            Logins l = new Logins();

            l.Login = tbLogin.Text;

            Emails em = new Emails();

            em.Email = tbEmail.Text;

            PhoneNumbers ph = new PhoneNumbers();

            ph.Phone = tbPhone.Text;

            if (p.IsCorrect(p.Password) == true && l.IsCorrect(l.Login) == true && em.IsCorrect(em.Email) == true && ph.IsCorrect(ph.Phone) == true)
            {
                if (CheckPsw(tbPassword.Text.ToString()))
                {
                    Users.Add(new User(tbLogin.Text, tbPassword.Text, tbEmail.Text, tbPhone.Text, dateTimeExpiration.Value));
                    listBoxUsers.Items.Add(Users[Users.Count - 1].ToString() + '\n');
                    tbPassword.BackColor = Color.White;
                    tbPhone.BackColor    = Color.White;
                    tbEmail.BackColor    = Color.White;
                    tbLogin.BackColor    = Color.White;
                }
                else
                {
                    MessageBox.Show("You're trying to enter the same password\n" +
                                    "You can't.Chenge it please");
                }
                endDate.Add(dateTimeExpiration.Value);
            }
            else if (p.IsCorrect(p.Password) == false)
            {
                if (tbPassword.BackColor != Color.Red)
                {
                    tbPassword.BackColor = Color.Red;
                    MessageBox.Show("Hey.It seems like you've made a mistake\n" +
                                    "in password field.You need to correct it");
                }
            }
            if (l.IsCorrect(l.Login) == false)
            {
                if (tbLogin.BackColor != Color.Red)
                {
                    tbLogin.BackColor = Color.Red;
                    MessageBox.Show("How did you manage to make a mistake \n" +
                                    "in a Login field? Correct it before anyone sees it");
                }
            }
            if (em.IsCorrect(em.Email) == false)
            {
                if (tbEmail.BackColor != Color.Red)
                {
                    tbEmail.BackColor = Color.Red;
                    MessageBox.Show("Another mistake\n" +
                                    "Will you correct it?");
                }
            }
            if (ph.IsCorrect(ph.Phone) == false)
            {
                if (tbPhone.BackColor != Color.Red)
                {
                    tbPhone.BackColor = Color.Red;
                    MessageBox.Show("Just correct it.Please");
                }
            }
        }