Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Connection String
            SqlConnection con = new SqlConnection(@"Data Source=(localdb)\ProjectsV13;Initial Catalog=StudentManagement;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False");
            SqlCommand    cmd = new SqlCommand("SELECT UserID FROM [dbo].[logins] WHERE LoginName=@pLoginName AND PasswordHash=HASHBYTES('SHA2_512', @pPassword+CAST(Salt AS NVARCHAR(73)))", con);

            cmd.Parameters.AddWithValue("@pLoginName", textBox1.Text);
            cmd.Parameters.AddWithValue("@pPassword", textBox2.Text);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataTable      dt  = new DataTable();

            sda.Fill(dt);
            // Connection open here
            con.Open();
            int i = cmd.ExecuteNonQuery();

            con.Close();
            if (dt.Rows.Count > 0)
            {
                MessageBox.Show("Successfully logged in");
                this.Hide();
                Homeform homeForm = new Homeform();
                homeForm.Show();
            }
            else
            {
                MessageBox.Show("Please enter Correct Username and Password");
            }
        }
        private void HomeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Hide();
            Homeform homeForm = new Homeform();

            homeForm.Show();
        }