3

I am developing a website which will authenticate the user and change the old password with new password.

I am using WinNT string connection and setting password, without the old password check, works.

My code is as below:

'actual setting password
            Dim entryD As New DirectoryEntry("WinNT://" + Environment.MachineName + ",computer")

            Dim NewUser As DirectoryEntry = entryD.Children.Find(username, "user")


            Dim nativeobject As Object = NewUser.NativeObject
            NewUser.Invoke("SetPassword", New Object() {strPassNew})

            NewUser.CommitChanges()
            'setting password ends

This works fine, but authentication code is not working.

It is as below:

'authentication starts
            Dim adsiPath As String

            adsiPath = String.Format("WinNT://{0}/{1},user", domain, username)

            Dim userEntry = New DirectoryEntry(adsiPath, username, password, AuthenticationTypes.Secure)

            'Dim nativeobject1 As Object = userEntry.NativeObject

            Dim newobj As ActiveDs.IADsUser = userEntry.NativeObject


            authent = True

            'authentication ends

This authenticates but the exception which it throws is:

logon failure: unknown username or bad password

for the first time, but if i do it again the error is:

"Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again. "

Which I don't want to happen... I don't want to use LDAP, I want a solution please, to authenticate the old password. Please help?

leoraelkins
  • 173
  • 1
  • 1
  • 13
shradha
  • 147
  • 2
  • 16
  • 2
    what line is the exception? I dont see where your actually authenticating? see these threads: http://stackoverflow.com/questions/400872/active-directory-check-username-password and http://stackoverflow.com/questions/290548/c-sharp-validate-a-username-and-password-against-active-directory – Jeremy Thompson Apr 21 '12 at 09:08
  • Dim newobj As ActiveDs.IADsUser = userEntry.NativeObject i get the exception on this line. – shradha Apr 21 '12 at 09:26
  • Dim userEntry = New DirectoryEntry(adsiPath, username, password, AuthenticationTypes.Secure) this is the line i m using to authenticate, – shradha Apr 21 '12 at 09:27
  • 1
    is there anything in the event logs? are you following any sample code/article? are all the codes permissions ok - like perhaps the error message is misleading and means its not the users credentials its the applications? – Jeremy Thompson Apr 21 '12 at 09:39

1 Answers1

0

I had this error in my code where requirement was to add domain users to local admin group of a system. While testing the code after the first try I used to get "Multiple connections to a server ..." error and then I if try the code code later(an hour or so) it worked fine. After searching thru various forms I came know the we can see user logged-on to a computer using

NET SESSION /LIST

command in cmd of remote system and it appears that when we use WinNT provider it actually creates an user session with idle timeout on remote computer (there can be a situation where other programs are creating sessions) which conflicts the connection when you try for second time. So I tried deleting the previous session by

NET SESSION \\RequestingComputerName /DELETE

then I did n't got the error. If that doesn't solve the problem then the last resort is to restart the system.

Vivek Raj
  • 459
  • 5
  • 16