cs_Dante27
Messages postés19Date d'inscriptionmardi 3 janvier 2006StatutMembreDernière intervention29 février 2008
-
28 janv. 2008 à 16:46
cs_ghuysmans99
Messages postés3982Date d'inscriptionjeudi 14 juillet 2005StatutMembreDernière intervention30 juin 2013
-
31 mars 2009 à 19:45
Bonjour à tous,
Je travaille actuellement sur un projet dans lequel il y aura une authentification par le biais du compte local windows; il faut donc pour ça récupérer le login et le mot de passe et les comparer par rapport à l'annuaire Active Directory.J'aurais voulu savoir si quelqu'un aurait une idée de la marche à suivre.
cs_ghuysmans99
Messages postés3982Date d'inscriptionjeudi 14 juillet 2005StatutMembreDernière intervention30 juin 201316 28 janv. 2008 à 20:55
Euh ... Ceci :
Option Explicit
Private Declare Function LogonUser Lib "advapi32.dll" Alias "LogonUserA" (ByVal lpszUsername As String, ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal dwLogonType As E_LogonType, ByVal dwLogonProvider As E_LogonProvider, ByRef phToken As Long) As Long
Public Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
Public Declare Function ImpersonateLoggedOnUser Lib "advapi32.dll" (ByVal hToken As Long) As Long
Public Declare Function RevertToSelf Lib "advapi32.dll" () As Long
Private Enum E_LogonType
'This logon type is intended for users who will be interactively using the computer, such as a user being logged on
'by a terminal server, remote shell, or similar process.
'This logon type has the additional expense of caching logon information for disconnected operations;
'therefore, it is inappropriate for some client/server applications,
'such as a mail server.
LOGON32_LOGON_INTERACTIVE = 2
'This logon type is intended for high performance servers to authenticate plaintext passwords.
'The LogonUser function does not cache credentials for this logon type.
LOGON32_LOGON_NETWORK = 3
'This logon type is intended for batch servers, where processes may be executing on behalf of a user without
'their direct intervention. This type is also for higher performance servers that process many plaintext
'authentication attempts at a time, such as mail or Web servers.
'The LogonUser function does not cache credentials for this logon type.
LOGON32_LOGON_BATCH = 4
'Indicates a service-type logon. The account provided must have the service privilege enabled.
LOGON32_LOGON_SERVICE = 5
'This logon type is for GINA DLLs that log on users who will be interactively using the computer.
'This logon type can generate a unique audit record that shows when the workstation was unlocked.
LOGON32_LOGON_UNLOCK = 7
'#If WindowsVersionInfo.GetWindowsVersionInfo.dwPlatformId <> WinNT Then
'This logon type preserves the name and password in the authentication package, which allows the server to make
'connections to other network servers while impersonating the client. A server can accept plaintext credentials
'from a client, call LogonUser, verify that the user can access the system across the network, and still
'communicate with other servers.
'NOTE: Windows NT: This value is not supported.
LOGON32_LOGON_NETWORK_CLEARTEXT = 8
'This logon type allows the caller to clone its current token and specify new credentials for outbound connections.
'The new logon session has the same local identifier but uses different credentials for other network connections.
'NOTE: This logon type is supported only by the LOGON32_PROVIDER_WINNT50 logon provider.
'NOTE: Windows NT: This value is not supported.
LOGON32_LOGON_NEW_CREDENTIALS = 9
'#End If
End Enum
Public Enum E_LogonProvider
'Use the standard logon provider for the system.
'The default security provider is negotiate, unless you pass NULL for the domain name and the user name
'is not in UPN format. In this case, the default provider is NTLM.
'NOTE: Windows 2000/NT: The default security provider is NTLM.
LOGON32_PROVIDER_DEFAULT = 0
End Enum
Public Enum E_LogonMethod
LOGON_WITH_PROFILE = &H1
LOGON_NETCREDENTIALS_ONLY = &H2
End Enum
Public Function Logon(UserName As String, PassWord As String, Domain As String) As Long
Dim tok As Long, r As Boolean
r = LogonUser(UserName, Domain, PassWord, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, tok)
If r Then
Logon = tok
Else
Logon = False
End If
End Function<hr />, ----
[code.aspx?ID=41455 Colorisation syntaxique par Renfield]
_______________________________________________________________________
VB.NETis good ...VB6is better
cs_ghuysmans99
Messages postés3982Date d'inscriptionjeudi 14 juillet 2005StatutMembreDernière intervention30 juin 201316 28 janv. 2008 à 20:56
Et encore une remarque sur ce code : si le résultat de la fonction est <> False, faire CloseHandle avec son résultat pour fermer le handle.
_______________________________________________________________________
VB.NETis good ...VB6is better
cs_Dante27
Messages postés19Date d'inscriptionmardi 3 janvier 2006StatutMembreDernière intervention29 février 2008 29 janv. 2008 à 09:34
Merci beaucoup pour ce bout de code, je suis en train de bien le comprendre pour pouvoir correctement m'en servir. Par contre, j'ai une autre question. L'authentification va se faire via une form contenant 2 Labels et 2 TextBox ainsi qu'un bouton connexion; quand je cliquerais sur connexion, je passerais en paramètre à la fonction Logon le contenu des 2 TextBox?
cs_ghuysmans99
Messages postés3982Date d'inscriptionjeudi 14 juillet 2005StatutMembreDernière intervention30 juin 201316 29 janv. 2008 à 17:32
Tout à fait ... un truc dans le genre :
Dim LogonResult As Long
LogonResult = Logon(Me.txt_UserName.Text, Me.txt_PassWord.Text, "tondomaine")
If LogonResult = False Then
MsgBox "Nom d'utilisateur et/ou mot de passe incorrect(s) !", vbExclamation, "Erreur"
Else
MsgBox "Identification réussie ...", vbInformation, "Info"
CloseHandle LogonResult 'ferme le handle
End If , ----
[code.aspx?ID=41455 Colorisation syntaxique par Renfield]
_______________________________________________________________________
VB.NETis good ...VB6is better
Vous n’avez pas trouvé la réponse que vous recherchez ?
cs_Djodu69
Messages postés43Date d'inscriptionlundi 17 décembre 2007StatutMembreDernière intervention29 avril 2010 4 août 2008 à 08:30
Bonjour,
J'essaye ce code avec Access2007 mais j'ai quelque soucis au niveau des déclarations de fonctions publiques au début du code. Y-a t'il quelqu'un qui est déjà essayé ce code ?
cs_Djodu69
Messages postés43Date d'inscriptionlundi 17 décembre 2007StatutMembreDernière intervention29 avril 2010 4 août 2008 à 09:02
C'est bon j'ai trouvé :) Juste à enlever les "public" devant les déclaration.
La question que je me pose maintenant est comment récupérer des infos du genre Prénom et Nom stocker sur l'AD ?
cs_ghuysmans99
Messages postés3982Date d'inscriptionjeudi 14 juillet 2005StatutMembreDernière intervention30 juin 201316 12 sept. 2008 à 23:28
Le 1er code que j'ai posté, tu le mets dans un module.
L'autre, dans l'évènement Click d'un bouton sur ton form.
Tu crées deux champs de texte : txt_UserName & txt_PassWord
_________________________________________________________________________
VB.NETis good ...VB6is better<
dvdavid2004
Messages postés2Date d'inscriptionlundi 26 mai 2003StatutMembreDernière intervention30 mars 2009 25 mars 2009 à 09:52
Bonjour,
Merci pour ce script qui fonctionne parfaitement.
J'ai juste une petite question.
Comment peux-t-on éviter de vérouiller le compte Active directory au bout de x essai ?
Car j'ai implémenté cette fonction dans mon application, mais je ne veux pas que les comptes AD soient verrouillés si plusieurs saisies incorrectes.
Cela fait un moment que je cherche, mais ne trouve rien à ce sujet...
Merci d'avance pour vos réponses
David
dvdavid2004
Messages postés2Date d'inscriptionlundi 26 mai 2003StatutMembreDernière intervention30 mars 2009 30 mars 2009 à 13:35
Merci ghuysmans, mais en fait je souhaite bien conserver la stratégie de verrouillage au bout de x essais pour une connexion Windows et la désactiver pour la connexion à mon application