begin process at 2008 08 20 15:46:34
1 228 926 membres
290 nouveaux aujourd'hui
14 259 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

Sujet : Authentification Active Directory sous VB6 [ Système / Sécurité ] (Dante27)

Authentification Active Directory sous VB6 le 28/01/2008 16:46:09

Dante27
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. Merci d'avance

Re : Authentification Active Directory sous VB6 le 28/01/2008 20:55:10

ghuysmans99
Membre Club
Réponse acceptée !
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
Colorisation syntaxique par Renfield
_______________________________________________________________________
VB.NETis good ...VB6is better

Re : Authentification Active Directory sous VB6 le 28/01/2008 20:56:27

ghuysmans99
Membre Club
Réponse acceptée !
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

Re : Authentification Active Directory sous VB6 le 29/01/2008 09:34:43

Dante27
Réponse acceptée !
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? Merci encore pour votre aide.

Re : Authentification Active Directory sous VB6 le 29/01/2008 17:32:40

ghuysmans99
Membre Club
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
Colorisation syntaxique par Renfield
_______________________________________________________________________
VB.NETis good ...VB6is better

Re : Authentification Active Directory sous VB6 le 30/01/2008 09:25:42

Dante27
Merci beaucoup, ca fonctionne parfaitement bien! Bonne journée

Re : Authentification Active Directory sous VB6 le 04/08/2008 08:30:11

Djodu69
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 ?

Merci par avance

Re : Authentification Active Directory sous VB6 le 04/08/2008 09:02:06

Djodu69
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 ?


Re : Authentification Active Directory sous VB6 le 04/08/2008 10:09:27

ghuysmans99
Membre Club
[ Lien ]
_________________________________________________________________________
VB.NET is good ... VB6 is better<


Classé sous : vb6, active, directory, authentification

Participer à cet échange

Pub



Appels d'offres

CalendriCode

Août 2008
LMMJVSD
    123
45678910
11121314151617
18192021222324
25262728293031

VS Express FR Gratuit !

VS Express en français et 100% gratuit !

Téléchargements

Logiciels à télécharger sur le même thème :

Boutique

Boutique de goodies CodeS-SourceS