Accueil > > > 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
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
Commentaires et avis
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 ça comme code mais pour un pass unique.<%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 afin de récupérer le login.message.fields("LOGON_USER")=Request.ServerVariables("LOGON_USER")Or par exemple si
Connection à SQL SERVER [ par jeremieuk ]
Bonjour,J'esssai en vains de me connecter à ma base SQL depuis un poste client.Voici mon messsage d'erreur:Type d'erreur :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 (
|
Derniers Blogs
XNA IS DEAD!XNA IS DEAD! par richardc
Depuis la semaine dernière (et grâce aux TechDays 2012), je me penche activement sur la nouvelle version de Windows, aka Windows 8. Vous me direz, il était temps puisque la première preview date de Septembre dernier.
OK. Remarquez, on n'en est qu'aux...
Cliquez pour lire la suite de l'article par richardc TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 !TECHDAYS PARIS 2012 : WINDOWS SERVER "8" QUOI DE 9 ! par ROMELARD Fabrice
Speakers: Fabrice Meillon et Stanislas Quastana Cette session est basée entièrement sur celle donnée lors de la BUILD cet hiver. Il n'y a pas d'ajout d'information en rapport avec cet évènement passé. Windows 8 Server sera intégralem...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE)[HTML5] AUTOUR DU W3C : NOUVEAUX STANDARDS ET WEB MOBILE (LILLE) par Gio
Je m'y prends un peu tard je sais, mais bon je suis développeur web et donc hyper fainéant ! Toujours dans le cadre des technologies émergentes, ici HTML5, parce qu'on aime HTML5 chez Wyg , nous seront présent, le vieux ( Aurélien V.) et moi, pour pr...
Cliquez pour lire la suite de l'article par Gio [WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz
Forum
RE : FORMULAIRERE : FORMULAIRE par ap24dp
Cliquez pour lire la suite par ap24dp RE : FORMULAIRERE : FORMULAIRE par jopop
Cliquez pour lire la suite par jopop RE : FORMULAIRERE : FORMULAIRE par ap24dp
Cliquez pour lire la suite par ap24dp RE : FORMULAIRERE : FORMULAIRE par jopop
Cliquez pour lire la suite par jopop
Logiciels
DocTranslate (V3.1.0.0)DOCTRANSLATE (V3.1.0.0)DocTranslate est un traducteur de document Microsoft Word, PowerPoint et Excel. Il permet d'autom... Cliquez pour télécharger DocTranslate Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System
|