Ejemplo n.º 1
0
        protected void Login_Click(object sender, EventArgs e)
        {
            /*Clase de membership*/
            SecurityUser ad = new SecurityUser();
            /*Valida si existe el CRM*/
            var resul = ad.ValuserShip(txtUsername.Text);
            if (resul.Equals(true))
            {
                String adPath = "LDAP://192.168.0.5/OU=MAYALES,DC=mayales,DC=local"; //direccion del dominio
                FormsAuth.LdapAuthentication adAuth = new FormsAuth.LdapAuthentication(adPath);
                try
                {
                    /*Autentificacion en membership*/
                    if (true == adAuth.IsAuthenticated(txtUsername.Text, txtPassword.Text))
                    {
                        String groups = adAuth.GetGroups();

                        //crea un ticket y añade el grupo
                        //bool isCookiePersistent = chkPersist.Checked;
                        FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, txtUsername.Text,
                        DateTime.Now, DateTime.Now.AddMinutes(60), false, groups);

                        //encripta el tiket.
                        String encryptedTicket = FormsAuthentication.Encrypt(authTicket);

                        //Creador de una cookie, y entonces añade la key encriptada a la cookie y ala data
                        HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

                        //if(true == isCookiePersistent)
                        authCookie.Expires = authTicket.Expiration;

                        //añade la cookie a la coleccion
                        Response.Cookies.Add(authCookie);
                        BLLHistorialIngreso his = new BLLHistorialIngreso();
                        his.InsertHistorial(txtUsername.Text);
                        //redireccion
                        Response.Redirect(FormsAuthentication.GetRedirectUrl(txtUsername.Text, false));
                    }
                    else
                    {   /*error label cuando la contraseña sea incorrecta*/
                        errorLabel.Text = "Verifique por favor el usuario y contraseña";
                    }
                }
                catch (Exception ex)
                {
                    /*Envia una excepcion cuando falla la autentificiacion*/
                    errorLabel.Text = "Error de autenticación.  " + ex.Message;
                }
            }
            else
            {   /*Envia este mensaje cuando el usuario no tiene acceso a mayales*/
                errorLabel.Text = "El usuario no tiene Acceso a CRM - Mayales";
            }
        }
Ejemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            String adPath = "LDAP://valvex.in";

            FormsAuth.LdapAuthentication lauth = new FormsAuth.LdapAuthentication(adPath);

            if (!lauth.IsAuthenticated("valvex.in", textBox1.Text, textBox2.Text))
            {
                MessageBox.Show("Błędny login lub hasło");
            }
            else
            {
                MainApp m = new MainApp(this.textBox1.Text);

                this.Hide();
                m.ShowDialog();
                this.Show();
                this.textBox2.Text = "";
            }
        }