Esempio n. 1
0
        public static bool resetLozinku(korisnik k, string novasifra)
        {
            if (proveraKorisnikaZaReset(k))
            {
                string     sql = "UPDATE korisnik SET [sifra] = @sifra WHERE [korisnickoIme] = @KorisnickoIme";
                SqlCommand cmd = new SqlCommand(sql, connect);
                cmd.Parameters.Add("@sifra", SqlDbType.Char).Value         = novasifra;
                cmd.Parameters.Add("@KorisnickoIme", SqlDbType.Char).Value = k.korisnickoIme;

                connect.Open();

                int rows = cmd.ExecuteNonQuery();

                connect.Close();

                if (rows > 0)
                {
                    return(true);
                }
                return(false);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        public static DataTable radniciBox(korisnik k)
        {
            connect.Open();
            SqlDataAdapter sda = new SqlDataAdapter("SELECT ime, prezime, brtelefona, korisnickoIme FROM korisnik WHERE tip='R'", connect);
            DataTable      dt  = new DataTable();

            sda.Fill(dt);
            connect.Close();
            return(dt);
        }
Esempio n. 3
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            korisnik  k  = new korisnik();
            DataTable dt = Base.radniciBox(k);

            if (dt.Rows.Count > 0)
            {
                textBox1.Text = dt.Rows[0][0].ToString();
                textBox2.Text = dt.Rows[0][1].ToString();
                textBox3.Text = dt.Rows[0][2].ToString();
                textBox5.Text = dt.Rows[0][4].ToString();
            }
            else
            {
                MessageBox.Show("Check username");
            }
        }
Esempio n. 4
0
        public static DataTable Login(korisnik k)
        {
            DataTable  dt  = new DataTable();
            string     sql = "SELECT * FROM korisnik WHERE korisnickoIme = @korisnickoIme AND sifra = @sifra ";
            SqlCommand cmd = new SqlCommand(sql, connect);

            cmd.Parameters.AddWithValue("@korisnickoIme", k.korisnickoIme);
            cmd.Parameters.AddWithValue("@sifra", k.sifra);

            SqlDataAdapter adapter = new SqlDataAdapter(cmd);

            connect.Open();
            adapter.Fill(dt);
            connect.Close();

            return(dt);
        }
Esempio n. 5
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox1.Text == "" || textBox2.Text == "" || textBox5.Text == "" || textBox6.Text == "")
                {
                    MessageBox.Show("You must fill in all fields");
                }
                else
                {
                    korisnik k = new korisnik();
                    k.korisnickoIme = textBox5.Text;
                    k.sifra         = textBox6.Text;
                    string allowedchar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                    if (textBox1.Text.Equals(textBox2.Text))
                    {
                        if (!textBox1.Text.All(allowedchar.Contains))
                        {
                            MessageBox.Show("Check password");
                        }

                        else if (k.promenaLozinke(textBox1.Text))
                        {
                            MessageBox.Show("Password changed successfully");
                        }

                        else
                        {
                            MessageBox.Show("Failed password change");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Incorrectly confirmed password");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 6
0
        //private static string hashLozinka(string lozinka)
        //{
        //    using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider())
        //    {
        //        UTF8Encoding utf8 = new UTF8Encoding();
        //        byte[] data = md5.ComputeHash(utf8.GetBytes(lozinka));
        //        return Convert.ToBase64String(data);
        //    }
        //}
        public static bool ProveraKorisnika(korisnik k)
        {
            string         sql     = "SELECT korisnickoIme FROM korisnik";
            SqlCommand     cmd     = new SqlCommand(sql, connect);
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);

            connect.Open();
            DataTable dt = new DataTable();

            adapter.Fill(dt);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (dt.Rows[i][0].ToString() == k.korisnickoIme)
                {
                    connect.Close();
                    return(true);
                }
            }
            connect.Close();
            return(false);
        }
Esempio n. 7
0
        private static bool proveraKorisnikaZaReset(korisnik k)
        {
            connect.Open();
            string     sql = "SELECT * FROM korisnik WHERE korisnickoIme = @KorisnickoIme AND sifra = @sifra";
            SqlCommand cmd = new SqlCommand(sql, connect);

            cmd.Parameters.AddWithValue("@KorisnickoIme", k.korisnickoIme);
            cmd.Parameters.AddWithValue("@sifra", k.sifra);

            SqlDataReader reader = cmd.ExecuteReader();

            if (reader.Read())
            {
                connect.Close();
                return(true);
            }
            else
            {
                connect.Close();
                return(false);
            }
        }
Esempio n. 8
0
        private void button1_Click(object sender, EventArgs e)
        {
            korisnik k = new korisnik();

            k.korisnickoIme = textBox5.Text;
            string allowedchar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

            k.sifra = textBox4.Text;

            if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text == "")
            {
                MessageBox.Show("You must fill in all the fields!");
            }
            else if (k.proveraKorisnika())
            {
                MessageBox.Show("Username already exists.");
            }
            else if (!textBox5.Text.All(allowedchar.Contains))
            {
                MessageBox.Show("Check the password.You have entered forbidden characters");
            }
            else if (!textBox4.Text.All(allowedchar.Contains))
            {
                MessageBox.Show("Check the username.You have entered forbidden characters!");
            }
            else
            {
                try
                {
                    Base.dodavanjeRadnika(textBox1.Text, textBox2.Text, textBox3.Text, textBox4.Text, textBox5.Text);
                    MessageBox.Show("Successful");
                }
                catch
                {
                    MessageBox.Show("Employee already exists!");
                }
            }
        }
Esempio n. 9
0
        private void button1_Click(object sender, EventArgs e)
        {
            korisnik k = new korisnik();

            k.korisnickoIme = textBox1.Text;
            k.sifra         = textBox2.Text;
            DataTable dt1         = Base.UlogujAdmina(k);
            DataTable dt          = Base.UlogujRadnika(k);
            string    allowedchar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

            try
            {
                if (textBox1.Text == "" || textBox2.Text == "")
                {
                    MessageBox.Show("Morate popuniti sva polja");
                }
                else if (!textBox2.Text.All(allowedchar.Contains))
                {
                    MessageBox.Show("Proverite lozinku");
                }
                else
                {
                    if (k.proveraKorisnika())
                    {
                        if (k.tip == "A")
                        {
                            if (dt1.Rows.Count == 1)

                            {
                                this.Hide();
                                Admin a = new Admin();
                                a.Show();
                            }
                            else
                            {
                                MessageBox.Show("Neispravno ste uneli lozinku.");
                            }
                        }
                        else
                        {
                            if (dt.Rows.Count == 1)
                            {
                                this.Hide();
                                User f = new User();
                                f.Show();
                            }
                            else
                            {
                                MessageBox.Show("Neispravno ste uneli lozinku.");
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Ne postoji korisnik sa unesenim korisničkim imenom");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 10
0
        private void button1_Click(object sender, EventArgs e)
        {
            string allowedchar = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

            if (textBox1.Text == "" || textBox2.Text == "")
            {
                MessageBox.Show("You must fill in all fields");
            }
            else if (!textBox2.Text.All(allowedchar.Contains))
            {
                MessageBox.Show("Check the password");
            }
            else
            {
                korisnik k = new korisnik();
                k.korisnickoIme = textBox1.Text;
                k.sifra         = textBox2.Text;
                DataTable dt = Base.Login(k);

                try
                {
                    if (k.proveraKorisnika())
                    {
                        if (dt.Rows.Count == 1)
                        {
                            switch (dt.Rows[0][5] as string)
                            {
                            case "A":
                            {
                                k.korisnickoIme = dt.Rows[0][4].ToString();
                                this.Hide();
                                Admin a = new Admin();
                                a.Show();
                                break;
                            }

                            case "R":
                            {
                                k.korisnickoIme = dt.Rows[0][4].ToString();
                                User u = new User();
                                u.Show();
                                break;
                            }

                            default:
                            {
                                MessageBox.Show("You entered your username or password incorrectly.");
                                break;
                            }
                            }
                        }
                        else
                        {
                            MessageBox.Show("You entered your username or password incorrectly.");
                        }
                    }
                    else
                    {
                        MessageBox.Show("There is no user with the username entered.");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }