Foros del Web » Programando para Internet » ASP Clásico »

Logarse contra directorio activo. Detectar contraseña caducada..

Estas en el tema de Logarse contra directorio activo. Detectar contraseña caducada.. en el foro de ASP Clásico en Foros del Web. Hola a todos, Es mi primer post en este foro, encantado de encontraros. Soy programador ocasional, y casi siempre en asp.net. mi primer post es ...
  #1 (permalink)  
Antiguo 13/03/2013, 07:23
 
Fecha de Ingreso: marzo-2013
Ubicación: Andalucia
Mensajes: 4
Antigüedad: 11 años, 8 meses
Puntos: 0
Logarse contra directorio activo. Detectar contraseña caducada..

Hola a todos,

Es mi primer post en este foro, encantado de encontraros.
Soy programador ocasional, y casi siempre en asp.net. mi primer post es un ladrillo tela de grande.

Tengo que hacer un cambio en la página de logado de la intranet de mi empresa, que está hecha en ASP clasico. El código funciona bien, pero tiene un problema a la funcion que comprueba las credenciales del usuario si todo va bien, funciona, pero luego da falsos negativos. Es decir, puede que un usuario esté metiendo bien el usuario y la contraseña, pero si su estado en el directorio activo es, contraseña caducada (tiene que cambiarla) o pendiente de cambiar contraseña, la función le devuelve que la contraseña es incorrecta. Yo eso lo tengo implementado en asp.net, pero no se como pasarlo a asp. Os pongo mi código actual en asp:

function validUserLDAP( strUsername, strpassword)
Set objConnection = Server.CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.provider ="ADsDSOObject"
objConnection.Properties("User ID") = strUsername
objConnection.Properties("Password") = strpassword
objConnection.Properties("Encrypt Password") = false
objConnection.Properties("ADSI Flag") = 1
objConnection.open "Active Directory Provider"

Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Searchscope") = 2
objCommand.CommandText ="select cn FROM 'LDAP://""10.zz.yy.xx' where sAMAccountname='" + strUsername + "'"
on error resume next
Set objRS = objCommand.Execute
response.write("<SCRIPT LANGUAGE='JavaScript'>alert('El error devuelto es el " & Err.Number & ".');</SCRIPT>")
If Err.Number <> 0 Then

ldap = 0
' response.Write "ERR:" & err.Description
Else
ldap = 1
End If
' response.Write "ERR:" & err.Description
validUserLDAP = ldap

End Function

El código anterior no me informa del estado del usuario, vamos como os digo, si está pendiente de cambiar contraseña....

¿alguien sabe como me lo puede dar?

Si no es así, os paso mi codigo en asp.net (VB) a ver si puedo pasarlo a asp

' Enums
Public Enum LogonType As Integer
'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

'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 Enum

Public Enum LogonProvider As Integer
'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
LOGON32_PROVIDER_WINNT35 = 1
LOGON32_PROVIDER_WINNT40 = 2
LOGON32_PROVIDER_WINNT50 = 3
End Enum

'DLLImports
Declare Auto Function LogonUser Lib "advapi32.dll" (ByVal lpszUsername As String, _
ByVal lpszDomain As String, ByVal lpszPassword As String, ByVal dwLogonType As LogonType, _
ByVal dwLogonProvider As LogonProvider, ByRef phToken As IntPtr) As Integer

Public Function usuarioYPassDM(tUsuario As String, tcontraseña As String) As Integer
Const ERROR_PASSWORD_MUST_CHANGE As Integer = 1907
Const ERROR_LOGON_FAILURE As Integer = 1326
Const ERROR_ACCOUNT_RESTRICTION As Integer = 1327
Const ERROR_ACCOUNT_DISABLED As Integer = 1331
Const ERROR_INVALID_LOGON_HOURS As Integer = 1328
Const ERROR_NO_LOGON_SERVERS As Integer = 1311
Const ERROR_INVALID_WORKSTATION As Integer = 1329
Const ERROR_ACCOUNT_LOCKED_OUT As Integer = 1909 'It gives this error if the account is locked, REGARDLESS OF WHETHER VALID CREDENTIALS WERE PROVIDED!!!
Const ERROR_ACCOUNT_EXPIRED As Integer = 1793
Const ERROR_PASSWORD_EXPIRED As Integer = 1330

Const LOGON32_LOGON_INTERACTIVE As Integer = 2
Const LOGON32_LOGON_NETWORK As Integer = 3
Const LOGON32_LOGON_BATCH As Integer = 4
Const LOGON32_LOGON_SERVICE As Integer = 5
Const LOGON32_LOGON_UNLOCK As Integer = 7
Const LOGON32_LOGON_NETWORK_CLEARTEXT As Integer = 8
Const LOGON32_LOGON_NEW_CREDENTIALS As Integer = 9
Const LOGON32_PROVIDER_DEFAULT As Integer = 0

Dim hToken As IntPtr
Dim hTokenDuplicate As IntPtr
Dim errorCode As Integer
Dim success As Boolean

Dim esError As String
'primero ver si es un usuario del dominio
' devolveremos true si son credenciales válidas, false si no

Try
If (Not LogonUser(tUsuario, "dm.empresa.es", tcontraseña, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, hToken)) Then

errorCode = Marshal.GetLastWin32Error()
Select Case errorCode
Case 0
usuarioYPassDM = 0 'todo bien
Case Else
usuarioYPassDM = errorCode
End Select


End If




Catch ex As Exception
usuarioYPassDM = 0
End Try
End Function

Etiquetas: activo, asp, contra, contraseña, directorio, select
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 20:10.