I have been scanning the internet for a few days now. That is not working. So now it is time to post!
I have read a few other posts on here about authentication but they do not match exactly.
We currently have an intranet app built in a mixture of asp and asp.net 1.1 and 2.0 written in VB .Net. We have a form where the user logs in and it authenticates against active directory successully in 2 ways:
1. The admin resets the password and the user logs in using that password (not forced to change)
2. The user changes their password themselves.
HOWEVER
When the admin resets the password and checks the box to "force the password change" the application does not work. Here is the code that is causing the problem (specifically the DirectoryEntry, that is where the code fails). I have walked through the debugger and the code works fine for the 2 conditions I described above, but returns a the following error message when the password is reset and the user is "forced" to change their password:
{"Logon failure: unknown user name or bad password."}
Expand|Select|Wrap|Line Numbers
- Public Function IsAuthenticated(ByVal strUserId As String, _
- ByVal strPassword As String) As Boolean
- Dim strDomainAndUsername As String = strDomain & "\" & strUserId
- entry = New DirectoryEntry(adPath, strDomainAndUsername, strPassword, AuthenticationTypes.Secure)
- Try
- Dim search As DirectorySearcher = New DirectorySearcher(entry)
- search.Filter = "(SAMAccountName=" & strUserId & ")"
- search.PropertiesToLoad.Add("cn")
- Dim result As SearchResult = search.FindOne()
- If (result Is Nothing) Then
- Return False
- End If
- Catch ex As Exception
- Throw New Exception("Error authenticating user. " & ex.Message)
- End Try
- Return True
- End Function
Thanks for your time,
Joe
Also, if there is any documentation that explains this better please let me know. What I have learned about Active Directory and authentication has been random posts and articles on the internet over the past few days.