Beispiel #1
0
        private void btnlogin_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtnombre.Text != "" && txtfecha.Text != "" && txttelefono.Text != "" && txtcorreo.Text != "" && txtusuario.Text != "" && txtpassword.Text != "" && txtpassword2.Text != "")
                {
                    Usuarios user = new Usuarios();
                    user.Nombre_Completo  = txtnombre.Text;
                    user.Fecha_Nacimiento = Convert.ToDateTime(txtfecha.Text);
                    user.Login_Name       = txtusuario.Text;
                    if (txtpassword.Text == txtpassword2.Text)
                    {
                        using (MD5 md5Hash = MD5.Create())
                        {
                            string cadenaEncriptada = HashMD5.GetMD5(md5Hash, txtpassword.Text);
                            user.Password = cadenaEncriptada;
                        }


                        user.Administrador = Convert.ToBoolean(chkadmin.Checked == true ? 1 : 0);
                        user.Telefono      = txttelefono.Text;
                        user.Correo        = txtcorreo.Text;
                        user.Estado        = true;
                        A.Usuarios.Add(user);
                        A.SaveChanges();
                        lblinfo.ForeColor = Color.LimeGreen;
                        lblinfo.Text      = "¡Creacion realizada exitosamente!";
                        txtnombre.Text    = txtfecha.Text = txttelefono.Text = txtcorreo.Text = txtusuario.Text = txtpassword.Text = txtpassword2.Text = "";
                        chkadmin.Checked  = false;
                        llenarcbo();
                    }
                    else
                    {
                        lblinfo.ForeColor = Color.DarkRed;
                        lblinfo.Text      = "¡Las contraseñas no coinciden!";
                        return;
                    }
                }
                else
                {
                    lblinfo.ForeColor = Color.DarkRed;
                    lblinfo.Text      = "¡Campos Vacios!";
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #2
0
        private void btnlogin_Click(object sender, EventArgs e)
        {
            try
            {
                var tblUsuario = Biblio.Usuarios.FirstOrDefault(x => x.Login_Name == txtuser.Text);

                if (tblUsuario == null)
                {
                    lbmessage.Text = "¡Ingrese un usuario y una contraseña valida!";
                }
                else
                {
                    if (tblUsuario.Estado)
                    {
                        using (MD5 md5Hash = MD5.Create())
                        {
                            if (HashMD5.VerfyMD5(md5Hash, txtpass.Text, tblUsuario.Password))
                            {
                                MiClaseMagica.Variables_Globales.ACTIVE_USER       = tblUsuario.PkID_Usuario;
                                MiClaseMagica.Variables_Globales.ACTIVE_USER_EMAIL = tblUsuario.Correo;
                                FrmMenuP mn = new FrmMenuP(tblUsuario.Login_Name, tblUsuario.Administrador);
                                mn.Show();
                                this.Hide();
                            }
                            else
                            {
                                lbmessage.Text = "¡Usuario o Contraseña Incorrectos!";
                            }
                        }
                    }
                    else
                    {
                        lbmessage.Text = "¡Usuario Desactivado! Contacte al Administrador";
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtnombre2.Text != "" || txtfechanac2.Text != "" || txttelefono2.Text != "" || txtcorreo2.Text != "" || txtusuario2.Text != "")
                {
                    string s          = cbousuarios.SelectedItem.ToString();
                    var    tblUsuario = A.Usuarios.FirstOrDefault(x => x.Nombre_Completo == s);
                    tblUsuario.Nombre_Completo  = txtnombre2.Text;
                    tblUsuario.Fecha_Nacimiento = Convert.ToDateTime(txtfechanac2.Text);
                    tblUsuario.Telefono         = txttelefono2.Text;
                    tblUsuario.Correo           = txtcorreo2.Text;
                    tblUsuario.Login_Name       = txtusuario2.Text;
                    tblUsuario.Administrador    = Convert.ToBoolean(chkadmin2.Checked == true ? 1 : 0);
                    tblUsuario.Estado           = Convert.ToBoolean(chkestado.Checked == true ? 1 : 0);

                    if ((txtpasswode.Text != txtpasswode2.Text))
                    {
                        lbinformativo.ForeColor = Color.DarkRed;
                        lbinformativo.Text      = "¡Contraseñas Distintas!";
                    }
                    else
                    {
                        if (txtpasswode.Text == "" && txtpasswode2.Text == "")
                        {
                            A.SaveChanges();
                            lbinformativo.ForeColor   = Color.LimeGreen;
                            lbinformativo.Text        = "¡Edicion realizada exitosamente!";
                            txtnombre2.Text           = txtfechanac2.Text = txttelefono2.Text = txtcorreo2.Text = txtusuario2.Text = txtpasswode2.Text = txtpasswode.Text = "";
                            cbousuarios.SelectedIndex = -1;
                            llenarcbo();
                            chkadmin2.Checked = chkestado.Checked = false;
                        }
                        else
                        {
                            if (txtpasswode.Text == txtpasswode2.Text)
                            {
                                using (MD5 md5Hash = MD5.Create())
                                {
                                    string cadenaEncriptada = HashMD5.GetMD5(md5Hash, txtpasswode.Text);
                                    tblUsuario.Password = cadenaEncriptada;
                                }
                                A.SaveChanges();
                                txtnombre2.Text           = txtfechanac2.Text = txttelefono2.Text = txtcorreo2.Text = txtusuario2.Text = txtpasswode2.Text = txtpasswode.Text = "";
                                chkadmin2.Checked         = chkestado.Checked = false;
                                cbousuarios.SelectedIndex = -1;
                                lbinformativo.ForeColor   = Color.LimeGreen;
                                lbinformativo.Text        = "¡Edicion realizada exitosamente!";
                                llenarcbo();
                            }
                        }
                    }
                }
                else
                {
                    lbinformativo.BackColor = Color.DarkRed;
                    lbinformativo.Text      = "Campos Vacios";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }