Beispiel #1
0
        private void FormMatriz_FormClosed(object sender, FormClosedEventArgs e)
        {
            FormMenuPrincipal promo = new FormMenuPrincipal();

            promo.Text          = FormLogin.nom_unidad;
            promo.StartPosition = FormStartPosition.CenterScreen;
            promo.Show();

            this.Close();
        }
Beispiel #2
0
        private void btn_back_Click(object sender, EventArgs e)
        {
            FormMenuPrincipal promo = new FormMenuPrincipal();

            promo.Text          = FormLogin.nom_unidad;
            promo.StartPosition = FormStartPosition.CenterScreen;
            promo.Show();

            this.Close();
        }
Beispiel #3
0
        private void btc_login_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txt_username.Text))
            {
                //Focus box before showing a message
                txt_username.Focus();
                MessageBox.Show("Enter your username", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                //Focus again afterwards, sometimes people double click message boxes and select another control accidentally
                txt_username.Focus();
                return;
            }
            else if (string.IsNullOrEmpty(txt_pass.Text))
            {
                txt_pass.Focus();
                MessageBox.Show("Enter your password", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                txt_pass.Focus();
                return;
            }
            //OK they enter a user and pass, lets see if they can authenticate
            using (DataTable dt = LookupUser(txt_username.Text))
            {
                if (dt.Rows.Count == 0)
                {
                    txt_username.Focus();
                    MessageBox.Show("Invalid username.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txt_username.Focus();
                    return;
                }
                else
                {
                    //Always compare the resulting crypto string or hash value, never the decrypted value
                    //By doing that you never make a call to Decrypt() and the application is harder to
                    //reverse engineer. I included the Decrypt() method here for informational purposes
                    //only. I do not recommend shipping an assembly with Decrypt() methods.
                    string dbPassword = Convert.ToString(dt.Rows[0]["password"]);
                    id_user     = Convert.ToString(dt.Rows[0]["id_usuario"]);
                    nom_usuario = Convert.ToString(dt.Rows[0]["nombrelargo"]);
                    string appPassword = txt_pass.Text; //we store the password as encrypted in the DB
                    if (string.Compare(dbPassword, appPassword) == 0)
                    {
                        //Logged in


                        //try
                        //{
                        //    var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                        //    var settings = configFile.AppSettings.Settings;
                        //    if (ChkUser.Checked)
                        //    {
                        //        Properties.Settings.Default.username = txt_username.Text;
                        //        Properties.Settings.Default.chkuser = ChkUser.Checked;
                        //    }
                        //    else
                        //    {
                        //        Properties.Settings.Default.username = "";
                        //        Properties.Settings.Default.chkuser = ChkUser.Checked;
                        //    }
                        //    if (ChkPass.Checked)
                        //    {
                        //        Properties.Settings.Default.contraseña = txt_pass.Text;
                        //        Properties.Settings.Default.chkpass = ChkPass.Checked;
                        //    }
                        //    else
                        //    {
                        //        Properties.Settings.Default.contraseña = "";
                        //        Properties.Settings.Default.chkpass = ChkPass.Checked;
                        //    }
                        //    configFile.Save(ConfigurationSaveMode.Modified);
                        //    ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name);
                        //}
                        //catch (ConfigurationErrorsException)
                        //{
                        //    Console.WriteLine("Error writing app settings");
                        //}

                        using (SqlConnection conn = new SqlConnection(Program.cnn67))
                        {
                            string         query = "select ac.id_acceso,ac.id_unidad,un.nombre_unidad,ac.nivel from M_RIESGO_accesos ac inner join M_RIESGO_unidad un on ac.id_unidad = un.id_unidad where ac.id_acceso='" + id_user + "';";
                            SqlCommand     cmd   = new SqlCommand(query, conn);
                            SqlDataAdapter da    = new SqlDataAdapter(cmd);
                            //DataTable dt = new DataTable();
                            DataSet ds = new DataSet();
                            da.Fill(ds, "tabla");
                            //string num;
                            //num = ds.Tables["tabla"].Select("nivel").ToString();
                            foreach (DataRow dr in ds.Tables["tabla"].Rows)
                            {
                                //Muestras los valores obteniendolos con el Índice o el Nombre de la columna,
                                //   de la siguiente manera:
                                nivel      = dr["nivel"].ToString();
                                nom_unidad = dr["nombre_unidad"].ToString();
                                id_unidad  = dr["id_unidad"].ToString();
                            }
                        }

                        //FormMenuPrincipal.login = true;
                        this.Hide();
                        FormMenuPrincipal promo = new FormMenuPrincipal();
                        promo.Text          = nom_unidad;
                        promo.StartPosition = FormStartPosition.CenterScreen;
                        promo.ShowDialog();
                    }
                    else
                    {
                        //You may want to use the same error message so they can't tell which field they got wrong
                        txt_pass.Focus();
                        MessageBox.Show("Invalid Password", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        txt_pass.Focus();
                        return;
                    }
                }
            }
        }