예제 #1
0
        public static void add(CLogin login)
        {
            SqlCommand sqlCommand = new SqlCommand("insert into login values (@id,@fn)", DBUtil.getSqlConnection());

            sqlCommand.Parameters.AddWithValue("@id", login.Username);
            sqlCommand.Parameters.AddWithValue("@fn", login.Password);
            sqlCommand.ExecuteNonQuery();
        }
예제 #2
0
        public static void updatePassword(CLogin login)
        {
            SqlCommand sqlCommand = new SqlCommand("update login set password = @id where username = @fn", DBUtil.getSqlConnection());

            sqlCommand.Parameters.AddWithValue("@id", login.Password);
            sqlCommand.Parameters.AddWithValue("@fn", login.Username);
            sqlCommand.ExecuteNonQuery();
        }
 private void btnAdd_Click(object sender, EventArgs e)
 {
     if (txtPassword.Text.Length > 7 && txtPassword.Text.Length < 10 && txtUsername.Text.Length > 7 && txtUsername.Text.Length < 11)
     {
         CLogin c = new CLogin();
         c.Username = txtUsername.Text;
         c.Password = txtPassword.Text;
         CLoginDB.add(c);
         DBUtil.closeSqlConnection();
         MessageBox.Show("Account added");
     }
 }
 private void btnChange_Click(object sender, EventArgs e)
 {
     if (isNew && isConfirm)
     {
         CLogin c = new CLogin();
         c.Password = tbConfirmPassword.Text;
         c.Username = Login.username;
         CLoginDB.updatePassword(c);
         DBUtil.closeSqlConnection();
         Login.initLogin();
         DialogResult result = MessageBox.Show("Password changed", "Change", MessageBoxButtons.OK, MessageBoxIcon.Information);
         if (result == System.Windows.Forms.DialogResult.OK)
         {
             this.Close();
         }
     }
 }
예제 #5
0
        public static List <CLogin> getAll()
        {
            List <CLogin> logins = new List <CLogin>();
            SqlCommand    cmd    = new SqlCommand();
            SqlDataReader reader;

            cmd.CommandText = "select * from login";
            cmd.CommandType = System.Data.CommandType.Text;
            cmd.Connection  = DBUtil.getSqlConnection();
            reader          = cmd.ExecuteReader();
            while (reader.Read())
            {
                CLogin login = new CLogin();
                login.Username = reader[0].ToString();
                login.Password = reader[1].ToString();
                logins.Add(login);
            }
            return(logins);
        }
 private void Login_Activated(object sender, EventArgs e)
 {
     if (changePassForm)
     {
         changePassForm = false;
         CLogin c = new CLogin();
         c.Username = txtUsername.Text;
         index      = logins.BinarySearch(c);
         if (index >= 0)
         {
             pictureBox1.Image = imageList1.Images[0];
             password          = logins.ElementAt <CLogin>(index).Password;
             isUser            = true;
         }
         else
         {
             pictureBox1.Image = imageList1.Images[1];
             isUser            = false;
         }
         for (int i = 0; i < logins.Count; i++)
         {
             String s = logins.ElementAt <CLogin>(i).Password;
             if (s.Equals(txtPassword.Text) && i == index)
             {
                 match = true;
                 break;
             }
             else
             {
                 match = false;
             }
         }
         if (isUser && match)
         {
             pictureBox2.Image = imageList1.Images[0];
             isPass            = true;
         }
         else
         {
             pictureBox2.Image = imageList1.Images[1];
             isPass            = false;
         }
         if (txtPassword.Text == "")
         {
             pictureBox2.Image = null;
         }
         if (txtUsername.Text == "")
         {
             pictureBox1.Image = null;
         }
         for (int i = 0; i < logins.Count; i++)
         {
             String s = logins.ElementAt <CLogin>(i).Password;
             if (s.Equals(txtPassword.Text) && i == index)
             {
                 match = true;
                 break;
             }
             else
             {
                 match = false;
             }
         }
         if (isUser && match)
         {
             pictureBox2.Image = imageList1.Images[0];
             isPass            = true;
         }
         else
         {
             pictureBox2.Image = imageList1.Images[1];
             isPass            = false;
         }
         if (txtPassword.Text == "")
         {
             pictureBox2.Image = null;
         }
         if (txtUsername.Text == "")
         {
             pictureBox1.Image = null;
         }
     }
     if (hydroForm)
     {
         txtPassword.Text = "";
         txtUsername.Text = "";
     }
 }