begin process at 2010 02 10 10:02:46
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Sécurité & Cryptage

 > PROTEGER SON APPLICATION, AUTHENTIFICATION PAR COMPTES SYSTÈME [GRACE A ACTIVE DIRECTORY]

PROTEGER SON APPLICATION, AUTHENTIFICATION PAR COMPTES SYSTÈME [GRACE A ACTIVE DIRECTORY]




 Description

Cliquez pour voir la capture en taille normale
Bonjour tout le monde
voici une petite application qui effectue une recherche des objets (Comptes utilisateurs humains du système) par des requettes dans AD et permet de lister les noms des comptes ainsi de vérifier les informations de login (Mot de passe)

Grace a ce code, on peut proteger nos application par l'authentification intégrée du système d'exploitation.

Source

  • using System;
  • using System.DirectoryServices;
  • using System.Management;
  • using System.Windows.Forms;
  • namespace ListeUtilisateursDuSystem
  • {
  • public partial class frmMain : Form
  • {
  • public frmMain()
  • {
  • InitializeComponent();
  • }
  • private void frmMain_Shown(object sender, EventArgs e)
  • {
  • // Lecture des nom d'utilisateurs.
  • GetSystemUsers();
  • }
  • private void btnClose_Click(object sender, EventArgs e)
  • {
  • //Sortir
  • this.Close();
  • Application.Exit();
  • }
  • private void GetSystemUsers()
  • {
  • this.Cursor = Cursors.WaitCursor;
  • try {
  • //Préparation
  • this.lblDomainName.Text = "";
  • this.lblMachineName.Text = "";
  • this.cbxUsers.Items.Clear();
  • //Lecture du nom de domaine
  • string localdomain = GetDomain();
  • //Lecture du nom de la machine.
  • string localpc = Environment.MachineName;
  • this.lblDomainName.Text += localdomain;
  • this.lblMachineName.Text += localpc;
  • Application.DoEvents();
  • //Si le nom de domaine est unconnu.
  • if (localdomain == string.Empty)
  • {
  • //L'objet dirEntry est un composant ajouté depuis le toolBox (Juste pour une info de +).
  • this.dirEntry.Path = "WinNT://" + localpc;
  • }
  • else
  • {
  • this.dirEntry.Path = "WinNT://" + localdomain + "/" + localpc;
  • }
  • //Prendre les utilisateurs humains de la machine
  • foreach (DirectoryEntry child in this.dirEntry.Children)
  • {
  • if (child.SchemaClassName == "User")
  • this.cbxUsers.Items.Add(child.Name);
  • }
  • }
  • catch (Exception ex)
  • {
  • MessageBox.Show("Erreur:" + ex.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
  • }
  • this.Cursor = Cursors.Default;
  • }
  • private string GetDomain()
  • {
  • try
  • {
  • //Requette de recheche sur les informations du système.
  • string squery = "SELECT * FROM Win32_ComputerSystem";
  • //Création d'un objet Management Searcher.
  • ManagementObjectSearcher mgmtsearch = new ManagementObjectSearcher(squery);
  • //Recherche l'entrée Domain dans la liste des infos système.
  • foreach (ManagementObject item in mgmtsearch.Get())
  • {
  • return (item["Domain"].ToString());
  • }
  • return string.Empty;
  • }
  • catch
  • {
  • return string.Empty;
  • }
  • }
  • private void btnConnect_Click(object sender, EventArgs e)
  • {
  • Connect(cbxUsers.Text, txtPassword.Text);
  • }
  • private void Connect(string userName, string password)
  • {
  • try
  • {
  • DirectoryEntry de = new DirectoryEntry("LDAP://localhost/CN=Users;DC=" + lblDomainName.Text, lblDomainName.Text + "/" + userName, password, AuthenticationTypes.Secure);
  • object test = de.NativeObject; // Si cette propriété peut etre lu, donc les informations de connexion sont correctes.
  • MessageBox.Show("Salut " + userName, "Authentication réussite", MessageBoxButtons.OK, MessageBoxIcon.Information);
  • }
  • catch(Exception e)
  • {
  • MessageBox.Show(e.Message, "Erreur:", MessageBoxButtons.OK, MessageBoxIcon.Error);
  • }
  • }
  • }
  • }
using System;
using System.DirectoryServices;
using System.Management;
using System.Windows.Forms;

namespace ListeUtilisateursDuSystem
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void frmMain_Shown(object sender, EventArgs e)
        {
            // Lecture des nom d'utilisateurs.
            GetSystemUsers();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            //Sortir
            this.Close();
            Application.Exit();
        }

        private void GetSystemUsers() 
        { 
            this.Cursor = Cursors.WaitCursor; 
            try { 
                //Préparation 
                this.lblDomainName.Text = ""; 
                this.lblMachineName.Text = ""; 
                this.cbxUsers.Items.Clear(); 
                //Lecture du nom de domaine 
                string localdomain = GetDomain(); 
                //Lecture du nom de la machine. 
                string localpc = Environment.MachineName;

                this.lblDomainName.Text += localdomain;
                this.lblMachineName.Text += localpc;
                Application.DoEvents(); 
                //Si le nom de domaine est unconnu. 
                if (localdomain == string.Empty) 
                { 
                    //L'objet dirEntry est un composant ajouté depuis le toolBox (Juste pour une info de +). 
                    this.dirEntry.Path = "WinNT://" + localpc; 
                } 
                else 
                { 
                    this.dirEntry.Path = "WinNT://" + localdomain + "/" + localpc; 
                } 
                //Prendre les utilisateurs humains de la machine
                foreach (DirectoryEntry child in this.dirEntry.Children) 
                { 
                    if (child.SchemaClassName == "User") 
                        this.cbxUsers.Items.Add(child.Name);
                } 
            } 
            catch (Exception ex) 
            {
                MessageBox.Show("Erreur:" + ex.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
            } 
            
            this.Cursor = Cursors.Default; 
        }
        private string GetDomain()
        {
            try
            {
                //Requette de recheche sur les informations du système. 
                string squery = "SELECT * FROM Win32_ComputerSystem";
                //Création d'un objet Management Searcher. 
                ManagementObjectSearcher mgmtsearch = new ManagementObjectSearcher(squery);
                //Recherche l'entrée Domain dans la liste des infos système. 
                foreach (ManagementObject item in mgmtsearch.Get())
                {
                    return (item["Domain"].ToString());
                }
                return string.Empty;
            }
            catch
            {
                return string.Empty;
            }
        }

        private void btnConnect_Click(object sender, EventArgs e)
        {
            Connect(cbxUsers.Text, txtPassword.Text);
        }

        private void Connect(string userName, string password)
        {
            try
            {
                DirectoryEntry de = new DirectoryEntry("LDAP://localhost/CN=Users;DC=" + lblDomainName.Text, lblDomainName.Text + "/" + userName, password, AuthenticationTypes.Secure);
                object test = de.NativeObject; // Si cette propriété peut etre lu, donc les informations de connexion sont correctes.
                MessageBox.Show("Salut " + userName, "Authentication réussite", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch(Exception e)
            {
                MessageBox.Show(e.Message, "Erreur:", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}


 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources du même auteur

Source avec Zip Source avec une capture Source .NET (Dotnet) ANALYSEUR LEXICAL ET SYNTAXIQUE DES FORMULES PROPOSITIONNELL...
Source avec Zip Source avec une capture Source .NET (Dotnet) GESTION DES SERVICES WINDOWS
Source avec Zip Source .NET (Dotnet) CREATION DES POINTS DE RESTAURATION SYSTÈME
Source avec Zip Source avec une capture Source .NET (Dotnet) SAVOIR L'ADRESSE PHYSIQUE (MAC) DES CARTES RÉSEAUX DE L'ORDI...
Source avec Zip Source .NET (Dotnet) [DÉBUTANTS] ANIMATION DES FENETRES, CHARME SPÉCIALE POUR VOT...

 Sources de la même categorie

Source .NET (Dotnet) CLASS POUR LES LOGIN par DanMor498
Source avec Zip Source avec une capture Source .NET (Dotnet) CALCUL D'EMPREINTES DE FICHIERS par lex35
Source avec Zip Source .NET (Dotnet) UTILISER (ET SIMPLIFIER) UN READERWRITERLOCKSLIM AVEC USING ... par TheManu
Source avec Zip Source avec une capture Source .NET (Dotnet) GÉNÉRATEUR DE CLÉS (KEYGEN) AVEC CLÉ PUBLIQUE ET PRIVÉE ET G... par stalmar
Source avec Zip Source avec une capture Source .NET (Dotnet) CRYPTAGE PAR CESAR par youma85

 Sources en rapport avec celle ci

Source .NET (Dotnet) [ACTIVEDIRECTORY] DÉTERMINE SI L'UTILISATEUR USERNAME EST ME... par Francks11
Source avec Zip Source avec une capture Source .NET (Dotnet) INTÉRACTION AVEC ACTIVE DIRECTORY par bernie666
Source avec Zip Source .NET (Dotnet) NETWORK SHARE : CONNEXION A UN PARTAGE RESEAU AVEC AUTHENTIF... par coq
Source avec Zip Source avec une capture Source .NET (Dotnet) COMPOSANT D'AUTHENTIFICATION SQLSERVER par gg00xiv

Commentaires et avis

Commentaire de jesusonline le 29/08/2008 00:23:47 administrateur CS

Bonjour,

Plutot que de faire ta propre fenêtre de login, tu peux utiliser celle de windows, Kenny Kerr explique tout ça ici : http://msdn.microsoft.com/fr-fr/library/aa480470.aspx

Commentaire de boutemine le 29/08/2008 01:30:09

Salut
ça c'est mieux,
J'ai pas vu cet article sinon, je profite de la fenetre de login du système,

Article tres intéressant

Merci

Commentaire de noussa8433 le 06/04/2009 09:23:55

bonjour
comment tu peut utiliser cette application pour réaliser une authentification unique avec les application oracle(cad après la vérification dans AD ensuite faire une vérification dans OID)
c une application très interréssante pour débuter un projet SSO

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

authentification LDAP en c# et ASP.NET [ par crapulas ] Bonjour, j'ai créé une page de connexion pour un site web evec des textbox, label etc... en ASP.NET et avec du c#Il est demandé à la personne de rentr Authentification automatique [ par AnoTreL ] Bonjour,j'ai crée une authentification LDAP et tout marche parfaitement, mais maintenant je voudrais que l'utilisateur puisse se connecter automatique problème ldapV3 et C#. [ par Imirk ] Bonjour,Voila je dois faire une requete vers un serveur qui ne comprend que le ldapV3, mon code est le suivant, mais il me renvoie une erreur une fois session et authentification [ par adoulti ] bonsoir,j'ai une méthode d' authentification dans un web service    WS_authentification  , elle ça marche bien , voici le code si dessouuuuuuuuus(à la session du client [ par adoulti ] bonsoir,j'ai une méthode d' authentification dans un web service    WS_authentification  , elle ça marche bien , voici le code si dessouuuuuuuuus(à la Sécuriser l'authentification avec session [ par yoris75 ] Sécuriser l'authentification avec session Bonjour <p class="M MAPI [ par Ziman ] Bonjour,je dois développer un tit log qui utilise MAPI (COM pour se connecter avec Exchange). En fait, là je fais un petit script qui permet juste de mettre en place la boite de dialogue (authentification) pour une application windows [ par souadsaid ] comment pourrais je mettre la boite de dialogue d'authentification en premiere vu??? avant la fenetre principale aider moi svp..... faire un couplage entre LDAP et la base de mon matériel (OBDC =>access) [ par purle1 ] bonjour, voila j'ai un projet de mettre en place un ACR120U SDK sous windows et on me demande de faire un couplage de la base de donnée de mon matérie SSO [ par noussa8433 ] bonjour,je veut faire un projet qui consiste à élaborer une application c# qui permet de faire un système d'authentification unique entre le système w


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,484 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales