Link to home
Start Free TrialLog in
Avatar of asalvadeo
asalvadeo

asked on

How authenticate a Window user?

Folks I have the following code in VB and would like do the same thing in .NE, could somebody help me?

'Purpose   :    Checks if a the NT password for a user is correct.
'Inputs    :
'UserName  :    Domain
'               username
'               Password
'Outputs   :    Returns True if the password and user name are valid.
'Notes     :    Windows NT and 2000 ONLY. Requires NT Admin account to run.
'##ModelId=3DB58B1C007C
Public Function AuthenticateUser(ByVal psNTDomain, ByVal psUserName, ByVal psPassword) As Boolean

'declare local variables
Dim sNTDomain As String
Dim sUserName As String
Dim sPassword As String
Dim oIADS As ActiveDs.IADsContainer
Dim pvError  As String

'setup error handler
On Error GoTo AuthenticateUser_ErrorHandler

    'Do some error handling.  Return false if ANY field isn't populated
    'check the domain parameter
    If IsNull(psNTDomain) Then
        Err.Raise -1, , "Invalid NT Domain -- Null"
    ElseIf IsEmpty(psNTDomain) Then
        Err.Raise -1, , "Invalid NT Domain -- Empty"
    ElseIf Len(Trim(psNTDomain & "")) = 0 Then
        Err.Raise -1, , "Invalid NT Domain - 0 Length String"
    Else
        sNTDomain = CStr(psNTDomain)
    End If
   
    'check the username parameter
    If IsNull(psUserName) Then
        Err.Raise -1, , "Invalid User Name -- Null"
    ElseIf IsEmpty(psUserName) Then
        Err.Raise -1, , "Invalid User Name -- Empty"
    ElseIf Len(Trim(psUserName & "")) = 0 Then
        Err.Raise -1, , "Invalid User Name - 0 Length String"
    Else
        sUserName = CStr(psUserName)
    End If
   
    'check the password parameter
    If IsNull(psPassword) Then
        Err.Raise -1, , "Invalid Password -- Null"
    ElseIf IsEmpty(psPassword) Then
        Err.Raise -1, , "Invalid Password -- Empty"
    ElseIf Len(Trim(psPassword & "")) = 0 Then
        Err.Raise -1, , "Invalid Password - 0 Length String"
    Else
        sPassword = CStr(psPassword)
    End If
   
    'create the object.  if this errors out, it will be picked up by the error handler.
    Set oIADS = GetObject("WinNT:").OpenDSObject("WinNT://" & _
                            sNTDomain, _
                            sUserName, _
                            sPassword, _
                            ADS_SECURE_AUTHENTICATION)
       
    'destroy the object. we didn't need it for anything (just wanted to verify it was created).
    Set oIADS = Nothing
   
    'clear any errors from variable
    'pvError = ""
   
    'flag the function (user is valid) as true
    AuthenticateUser = True
Exit Function
ASKER CERTIFIED SOLUTION
Avatar of naveenkohli
naveenkohli

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Daij-Djan
Daij-Djan

Tried the code converter yet?
Avatar of asalvadeo

ASKER

naveenkohli,

Could u give a exemple of the use of DirectoryService to do it?
Here are some examples on use of DirectoryServices..

http://www.netomatix.com/DirectoryServices.aspx