begin process at 2012 02 14 03:56:40
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Administration

 > CLASS : VALIDER UN LOGIN ET MOT DE PASSE SUR ACTIVE DIRECTORY (ASP.NET, C#)

CLASS : VALIDER UN LOGIN ET MOT DE PASSE SUR ACTIVE DIRECTORY (ASP.NET, C#)


 Information sur la source

Note :
8,5 / 10 - par 2 personnes
8,50 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Administration Source .NET ( DotNet ) Classé sous :activedirectory, login, user, connection, password Niveau :Débutant Date de création :12/11/2004 Date de mise à jour :14/11/2004 16:08:15 Vu :22 306

Auteur : Trinita16

Ecrire un message privé
Commentaire sur cette source (2)
Ajouter un commentaire et/ou une note

 Description

Je n'ai absolument pas réalisé le code ! Mais comme j'ai mis un peu de temps à trouver je le mais ici !

Pour plus de renseignement consulter les docs du msdn ici :

POUR LA CLASS DE CONNECTION :
http://msdn.microsoft.com/library/default.asp?ur l=/library/en-us/dnnetsec/html/SecNetHT02.asp

POU R L'EXPLICATION DU PATH :
http://msdn.microsoft.com/library/default.asp?ur l=/library/en-us/cpref/html/frlrfsystemdirectoryse rvicesdirectoryentryclasspathtopic.asp

Source

  • using System;
  • using System.Collections;
  • using System.DirectoryServices;
  • namespace FormsAuthAD
  • {
  • /// <summary>
  • /// Description résumée de ActiveDirectory.
  • /// </summary>
  • public class LdapAuthentication
  • {
  • public LdapAuthentication()
  • {
  • //
  • // TODO : ajoutez ici la logique du constructeur
  • //
  • }
  • public LdapAuthentication( string path )
  • {
  • _path = path;
  • }
  • private string _path;
  • private string _filterAttribute;
  • public bool IsAuthenticated(string domain, string username, string pwd)
  • {
  • string domainAndUsername = domain + @"\" + username;
  • DirectoryEntry entry = new DirectoryEntry( _path,
  • domainAndUsername,
  • pwd);
  • try
  • {
  • // Bind to the native AdsObject to force authentication.
  • Object obj = entry.NativeObject;
  • DirectorySearcher search = new DirectorySearcher(entry);
  • search.Filter = "(SAMAccountName=" + username + ")";
  • search.PropertiesToLoad.Add("cn");
  • SearchResult result = search.FindOne();
  • if(null == result)
  • {
  • return false;
  • }
  • // Update the new path to the user in the directory
  • _path = result.Path;
  • _filterAttribute = (String)result.Properties["cn"][0];
  • }
  • catch (Exception ex)
  • {
  • throw new Exception("Error authenticating user. " + ex.Message);
  • }
  • return true;
  • }
  • }
  • }
  • // UTILISATION DE LA CLASS EXEMPLE :
  • bool bResult = false;
  • LdapAuthentication MyAD = new LdapAuthentication( "LDAP://AdresseOuNomduserveurdedomaine" );
  • try
  • {
  • bResult = MyAD.IsAuthenticated( "Nomdudoaine","login", "Motdepasse" );
  • }
  • catch( Exception ExErreur )
  • {
  • messageLabel.Text = "Erreur Active Directory : "+ExErreur.Message;
  • }
using System;
using System.Collections;
using System.DirectoryServices;

namespace FormsAuthAD
{
	/// <summary>
	/// Description résumée de ActiveDirectory.
	/// </summary>
	public class LdapAuthentication
	{
		public LdapAuthentication()
		{
			//
			// TODO : ajoutez ici la logique du constructeur
			//
		}

		public LdapAuthentication( string path )
		{
			_path = path;
		}

		private string _path;
		private string _filterAttribute;

		public bool IsAuthenticated(string domain, string username, string pwd)
		{
			string domainAndUsername = domain + @"\" + username;
			DirectoryEntry entry = new DirectoryEntry( _path, 
				domainAndUsername,
				pwd);

			try
			{ 
				// Bind to the native AdsObject to force authentication.
				Object obj = entry.NativeObject;
				DirectorySearcher search = new DirectorySearcher(entry);
				search.Filter = "(SAMAccountName=" + username + ")";
				search.PropertiesToLoad.Add("cn");
				SearchResult result = search.FindOne();
				if(null == result)
				{
					return false;
				}
				// Update the new path to the user in the directory
				_path = result.Path;
				_filterAttribute = (String)result.Properties["cn"][0];
			}
			catch (Exception ex)
			{
				throw new Exception("Error authenticating user. " + ex.Message);
			}
			return true;
		}

		
	}
}


// UTILISATION DE LA CLASS EXEMPLE :
bool bResult = false;
LdapAuthentication MyAD = new LdapAuthentication( "LDAP://AdresseOuNomduserveurdedomaine" );

try
{
       bResult = MyAD.IsAuthenticated( "Nomdudoaine","login", "Motdepasse" );		
}
catch( Exception ExErreur )
{
     messageLabel.Text = "Erreur Active Directory : "+ExErreur.Message;
}	

 Conclusion

PS : Tester sous Windows 2000


 Historique

14 novembre 2004 16:08:16 :

 Sources de la même categorie

Source .NET (Dotnet) UTILISATION DES DATATABLES ET L'AFFICHAGE DU CONTENU DANS UN... par hedi_tounsi
Source .NET (Dotnet) RÉCUPÉRATION DES GROUPES AD D'UN USER EN ASPNET par DemonFire21
Source avec Zip Source avec une capture Source .NET (Dotnet) .NET2 GESTIONNAIRE DE DROITS DE FICHIERS AVEC SQL SERVER EN ... par gldfdp
Source avec Zip AUTHENTIFICATION D'UTILISATEURS AVEC BASE DE DONNÉES par Nurgle
Source avec Zip Source avec une capture SITE DYNAMIQUE + GÉNÉRATEUR DE STATS + ESPACE SÉCURISÉE EN F... par Batman69

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture UN CHAP LOGIN STYLÉ EN ASP3, AVEC UNE BDD EN MYSQL ET QUI SU... par ghuysmans99
Source .NET (Dotnet) ESPACE MEMBRE (CONNEXION, INSCRIPTION, MOT DE PASSE PERDU, E... par astuces_jeux
Source avec Zip Source .NET (Dotnet) GESTION DES UTILISATEURS par jarod_mmc
MOT DE PASSE ET LOGIN SIMPLE TOUT PRET, SANS MDB par GillesWebmaster
Source avec Zip ACCÉDER À UNE PAGE AVEC CONNECTION par vbtom

Commentaires et avis

Commentaire de quentincabo le 12/02/2008 16:25:41

C'est bien gentil mais est- il vraiment utilisable met le dans initié l'active directory n'est pas aussi simple que cela.

Mais le geste est très beau

Commentaire de sara20059 le 25/06/2010 02:39:03

Bonsoir merci pour votre adorable geste. Mais j'ai un petit probleme..Quand j'ajoute cette classe a mon site en asp.net et j'instancie pour utiliser ces methodes ,la classe n'ai pas reconnue :s.S'il vous plait ,si vous pourrez m'aidez.

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

Information formulaire (A laide) [ par rich25200 ] Bonjour,En ASP j'ai un formulaire login et password et je veux quand je clique sur indentifier celui ci m'éxécute un script "identifier.asp" et dans s Authentification windows [ par sergemercoeur ] Bonjour,Voici mon petit problème :Depuis la mise à jour de sécurité Microsoft IE 832894, il n'est plus possible d'envoyer dans l'url les infos de user authentification (login et password) pour espace verouille [ par mezzanine ] Bonjour,Je me présente Mezzanine, apprenti developpeurs (débutant).Je vous expose mon problème :Je souhaite par l'intermédiaire d'un formulaire (login Login et Password [ par timmzzz2904 ] hello, g &#231;a comme code mais pour un pass unique.&lt;%Response.Expires = 0Response.Expiresabsolute = Now() - 1Response.AddHeader "pragma","no-cach Login failed for user 'XXXX'. Reason: Not associated with a trusted SQL Server connection. [ par kccja ] [Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'XXXX'. Reason: Not associated with a trusted SQL Server connection. J'ai le mess probleme recuperation login [ par justone72 ] BonjourJ'utilise ce code&nbsp;afin de r&#233;cup&#233;rer le login.message.fields("LOGON_USER")=Request.ServerVariables("LOGON_USER")Or par exemple si Connection à SQL SERVER [ par jeremieuk ] Bonjour,J'esssai&nbsp; en vains de me connecter &#224; ma base SQL depuis un poste client.Voici mon messsage d'erreur:Type d'erreur&nbsp;:Microsoft OL Redirection [ par vince94 ] Salut,J'ai un formulaire qui vérifie les login password de l'utilisateur dans un script. Si elle est bonne ça donne accès à une page sinon, ça revien Récupération Login NT4 du client [ par chucky ] Bonjour à tous, je recherche désespérement une méthode pour récupérer le user NT4 de l'utilisateur mais sans succès. Plusieurs sources sont proposées fonction login et password [ par trop_facile ] Bonjour, Je suis entrain de créer un site internet. J'ai programmé une DB que j'ai fait avec MSSqlServer. je développe le site en C#, html et DOTNET (


Nos sponsors


Sondage...

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
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 : 1,186 sec (3)

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