Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(textBox1.Text))
            {
                MessageBox.Show("Por favor ingrese un servidor o nombre de base de datos.");
            }
            else
            {
                if (!String.IsNullOrEmpty(this.textBox2.Text) && !String.IsNullOrEmpty(this.textBox3.Text))
                {
                    String prevConnectionString = TrabajoDeCampo.Properties.Settings.Default.ConnectionString; // encriptado
                    String connectionString     = "Data Source=" + this.textBox1.Text + ";Initial Catalog=TRABAJO_DIPLOMA; User ID=" + this.textBox2.Text + ";Password="******"TRABAJO_DIPLOMA", "master")));
                    ServicioSeguridad servicioSeguridad = new ServicioSeguridad();

                    Boolean conecto = servicioSeguridad.probarConexion();
                    if (!conecto)
                    {
                        TrabajoDeCampo.Properties.Settings.Default.ConnectionString = prevConnectionString;
                        MessageBox.Show("No se pudo establecer una conexión con la base de datos");
                    }
                    else
                    {
                        MessageBox.Show("Conexión exitosa");
                        //usuario sistema
                        Usuario usu = new Usuario();
                        usu.id = 1L;
                        servicioSeguridad.grabarBitacora(usu, "Se regeneró el string de conexión", CriticidadEnum.ALTA);
                        Login login = new Login();

                        this.Hide();
                        login.Show();
                        this.Close();
                    }
                }
                else
                {
                    String prevConnectionString = TrabajoDeCampo.Properties.Settings.Default.ConnectionString; // encriptado

                    String cs  = "Data Source=" + this.textBox1.Text + ";Initial Catalog=TRABAJO_DIPLOMA;Integrated Security=True";
                    String mcs = "Data Source=" + this.textBox1.Text + ";Initial Catalog=master;Integrated Security=True";



                    TrabajoDeCampo.Properties.Settings.Default.ConnectionString = Convert.ToBase64String(Encoding.UTF8.GetBytes(cs));
                    TrabajoDeCampo.Properties.Settings.Default.MasterString     = Convert.ToBase64String(Encoding.UTF8.GetBytes(mcs));

                    ServicioSeguridad servicioSeguridad = new ServicioSeguridad();

                    Boolean conecto = servicioSeguridad.probarConexion();
                    if (!conecto)
                    {
                        TrabajoDeCampo.Properties.Settings.Default.ConnectionString = prevConnectionString;
                        MessageBox.Show("No se pudo establecer una conexión con la base de datos");
                    }
                    else
                    {
                        MessageBox.Show("Conexión exitosa");
                        Login   login = new Login();
                        Usuario usu   = new Usuario();
                        usu.id = 1L;
                        servicioSeguridad.grabarBitacora(usu, "Se regeneró el string de conexión", CriticidadEnum.ALTA);
                        this.Hide();
                        login.Show();
                        this.Close();
                    }
                }
            }
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            ServicioSeguridad servicioSeguridad = new ServicioSeguridad();
            string            user = this.txtUsername.Text;
            string            pass = this.txtPassword.Text;

            if (String.IsNullOrEmpty(user) || String.IsNullOrEmpty(pass))
            {
                Usuario usuario = new Usuario();
                usuario.id = 1L;
                StringBuilder sb = new StringBuilder();
                sb.Append("Alguien intentó ingresar sin completar los campos");
                if (!String.IsNullOrEmpty(user))
                {
                    sb.Append(", con este alias: " + user);
                }
                servicioSeguridad.grabarBitacora(usuario, sb.ToString(), CriticidadEnum.ALTA);
                MessageBox.Show("Complete los campos requeridos");
                this.txtUsername.Clear();
                this.txtPassword.Clear();
                this.txtUsername.Focus();
                return;
            }
            if (!alphanumericRegex.IsMatch(user) || !alphanumericRegex.IsMatch(pass))
            {
                MessageBox.Show("Los campos solo admiten letras y números");
                this.txtUsername.Clear();
                this.txtPassword.Clear();
                this.txtUsername.Focus();
                return;
            }
            try
            {
                servicioSeguridad.loguear(user, pass, null);

                Seguridad.Menu menu = new Seguridad.Menu();
                this.Close();
                menu.ShowDialog();
            }
            catch (Exception ex)
            {
                String mensaje = ex.Message;
                if (mensaje == "ALIAS" || mensaje == "PASS")
                {
                    MessageBox.Show("Su usuario o contraseña son incorrectos");
                    this.txtUsername.Clear();
                    this.txtPassword.Clear();
                    this.txtUsername.Focus();
                }
                else if (mensaje == "BLOQUEADO")
                {
                    MessageBox.Show("Su usuario se encuentra bloqueado, se ha restablecido su contraseña y enviado la misma a su mail");
                    this.txtUsername.Clear();
                    this.txtPassword.Clear();
                    this.txtUsername.Focus();
                }
                else if (mensaje == "PERMISOS")
                {
                    MessageBox.Show("El sistema se encuentra bloqueado, contacte al administrador");
                    this.txtUsername.Clear();
                    this.txtPassword.Clear();
                    this.txtUsername.Focus();
                }
                else
                {
                    MessageBox.Show("A ocurrido un error inesperado: " + mensaje);
                    this.txtUsername.Clear();
                    this.txtPassword.Clear();
                    this.txtUsername.Focus();
                }
            }
        }