Foros del Web » Programando para Internet » ASPX (.net) »

Cambio de Clave en el Ldap

Estas en el tema de Cambio de Clave en el Ldap en el foro de ASPX (.net) en Foros del Web. Buenas Tardes, colegas tengo este problema no se si alguno me pueda ayudar.. necesito saber si hay alguna aplicacion web que permita al usuario cambiar ...
  #1 (permalink)  
Antiguo 21/07/2010, 12:43
 
Fecha de Ingreso: diciembre-2009
Mensajes: 85
Antigüedad: 14 años, 4 meses
Puntos: 0
Cambio de Clave en el Ldap

Buenas Tardes, colegas tengo este problema no se si alguno me pueda ayudar..
necesito saber si hay alguna aplicacion web que permita al usuario cambiar su clave del directorio activo..
  #2 (permalink)  
Antiguo 21/07/2010, 13:16
Avatar de jaullo  
Fecha de Ingreso: abril-2009
Mensajes: 994
Antigüedad: 15 años
Puntos: 30
Respuesta: Cambio de Clave en el Ldap

Da una mirada a esto, puede que te oriente

Código ASP:
Ver original
  1. Private Sub ChangeUserADPassword(ByVal Username As String, ByVal Password As String, ByVal newPwd As String)
  2.  
  3.                 Dim dcDNS As String = "whatever.com"
  4.                 Dim rootDN As String
  5.                 Dim rootDSE As DirectoryEntry
  6.                 Dim searchRoot As DirectoryEntry
  7.                 Dim userEntry As DirectoryEntry
  8.                 Dim searcher As DirectorySearcher
  9.                 Dim results As SearchResultCollection
  10.                 Dim result As SearchResult
  11.                 Dim oldPassword As String = Password
  12.                 Dim newPassword As String = newPwd
  13.  
  14.                 Try
  15.                         '=========================================================================
  16.                         'Here I am binding the directory to the root with the current
  17.                         'users name and password instead of using an admin login to authenticate
  18.                         'The reason for this is that the users are not admin and only admin
  19.                         'can use the setpassword invoke method. thus, authenticated users will
  20.                         'use the change password method
  21.                         'note the authenicationtypes here
  22.                         'you need to either use SecureSocketsLayer or Kerberos (Secure + Sealing)
  23.  
  24.                         result = Nothing
  25.  
  26.                         rootDSE = New DirectoryEntry(String.Format("LDAP://{0}/rootDSE", _
  27.                         dcDNS), Username, oldPassword, AuthenticationTypes.Secure Or _
  28.                         AuthenticationTypes.Sealing Or AuthenticationTypes.ServerBind)
  29.  
  30.                         rootDN = DirectCast(rootDSE.Properties("defaultNamingContext").Value, String)
  31.                         searchRoot = New DirectoryEntry(String.Format("LDAP://{0}/{1}", _
  32.                         dcDNS, rootDN), Username, oldPassword, AuthenticationTypes.Secure Or _
  33.                         AuthenticationTypes.Sealing Or AuthenticationTypes.ServerBind)
  34.                         '==================================================================
  35.                         '------------------------------------------------------------------------
  36.                         'Find the user by their username in the directory using the
  37.                         'DirectorySearcher()
  38.  
  39.                         searcher = New DirectorySearcher(searchRoot)
  40.                         searcher.Filter = String.Format("sAMAccountName={0}", Username)
  41.                         searcher.SearchScope = SearchScope.Subtree
  42.                         searcher.CacheResults = False
  43.  
  44.                         results = searcher.FindAll
  45.  
  46.                         '-------------------------------------------------------------------------
  47.  
  48.                         '*****************************************************
  49.                         For Each result In results
  50.                                 'only use this method on .NET 1.1 or higher
  51.                                 'otherwise, get the adsPath value and build a new
  52.                                 'DirectoryEntry with the supplied credentials
  53.                                 userEntry = result.GetDirectoryEntry()
  54.                                 Exit For
  55.                                 'this is redundant because sAMAccountName is unique
  56.                                 'in the domain, but it is done for clarity
  57.                                 'Bind the user's DirectoryEntry (found from result search)
  58.                         Next
  59.                         'result = Nothing
  60.                         userEntry = result.GetDirectoryEntry()
  61.                         If userEntry Is Nothing Then
  62.                                 Label4.Text = "User not found in this domain."
  63.                                 Exit Sub
  64.                         End If
  65.  
  66.                         'Invoke the ChangePassword method (not the SetPassword method, since that
  67.                         'is used by admins to reset a password)
  68.  
  69.                         userEntry.Invoke("ChangePassword", New Object() {oldPassword, newPassword})
  70.                         userEntry.CommitChanges()
  71.  
  72.                         '****************************************************
  73.  
  74.                         Label4.Text = "Password Changed Successfully"
  75.                         If Not Session("User") Is Nothing Then
  76.                                 txtuser.Text = CStr(Session("User"))
  77.                                 GetUserPasswordADInfo(CStr(Session("User")))
  78.                         Else
  79.                                 GetUserPasswordADInfo(Trim(txtuser.Text))
  80.                         End If
  81.                 Catch ex As Exception 'System.Reflection.TargetInvocationException
  82.                         Label4.Text = ex.Message
  83.                 Finally 'these prevent other memory leaks
  84.                         userEntry = Nothing
  85.                         If Not userEntry Is Nothing Then userEntry.Dispose()
  86.                         results = Nothing
  87.                         If Not results Is Nothing Then results.Dispose()
  88.                         searcher = Nothing
  89.                         If Not searcher Is Nothing Then searcher.Dispose()
  90.                         searchRoot = Nothing
  91.                         If Not searchRoot Is Nothing Then searchRoot.Dispose()
  92.                         rootDSE = Nothing
  93.                         If Not rootDSE Is Nothing Then rootDSE.Dispose()
  94.                 End Try
  95.  
  96.         End Sub
__________________
http://geekswithblogs.net/jaullo/Default.aspx
Si te he ayudado regalame Karma positivo!!!
  #3 (permalink)  
Antiguo 21/07/2010, 13:35
 
Fecha de Ingreso: diciembre-2009
Mensajes: 85
Antigüedad: 14 años, 4 meses
Puntos: 0
Respuesta: Cambio de Clave en el Ldap

gracias por tu pronta res`puesta colega, olvide mensionar que estoy recien comenzando en este mundo de la programacion sera que me puedes guiar un poco mas y disculpa.
  #4 (permalink)  
Antiguo 21/07/2010, 14:58
Avatar de jaullo  
Fecha de Ingreso: abril-2009
Mensajes: 994
Antigüedad: 15 años
Puntos: 30
Respuesta: Cambio de Clave en el Ldap

De acuerdo, este procedimiento podrías utilizarlo en una página web y colocarlo en el evento de un boton para que sea ejecutado. Como ves el codigo esta un poco comentado en ingles pero esta.

Basicamente lo que necesitas cambiar es la direccion del LDAP (que se ve en rojo) y si ves el procedimiento recibe como parametros el nombre de usuario, el password actual y el nuevo password.

Trata de implementarlo, y cualquier duda preguntas.
__________________
http://geekswithblogs.net/jaullo/Default.aspx
Si te he ayudado regalame Karma positivo!!!
  #5 (permalink)  
Antiguo 22/07/2010, 07:24
 
Fecha de Ingreso: diciembre-2009
Mensajes: 85
Antigüedad: 14 años, 4 meses
Puntos: 0
Respuesta: Cambio de Clave en el Ldap

Gracias por tu paciencia y la ayuda, te cuento que he realizado: cree un proyecto en VB coloque un boton y dentro de el coloque el codigo antes indicado por ti pero pero me arroja los siguientes errores DirectoryEntry no definido, AuthenticationTypes no se ha declarado el nombre, disculpa mi ignorancia y gracias nuevamente.
  #6 (permalink)  
Antiguo 22/07/2010, 08:33
Avatar de jaullo  
Fecha de Ingreso: abril-2009
Mensajes: 994
Antigüedad: 15 años
Puntos: 30
Respuesta: Cambio de Clave en el Ldap

Prueba esta linea asi, colocalo todo en una sola línea


Código ASP:
Ver original
  1. rootDSE = New DirectoryEntry(String.Format("LDAP://{0}/rootDSE", dcDNS), Username, oldPassword, AuthenticationTypes.Secure Or AuthenticationTypes.Sealing Or AuthenticationTypes.ServerBind)

Importa el espacio de nombres
System.DirectoryServices

http://directoryprogramming.net/forums/thread/2385.aspx
__________________
http://geekswithblogs.net/jaullo/Default.aspx
Si te he ayudado regalame Karma positivo!!!
  #7 (permalink)  
Antiguo 22/07/2010, 09:19
 
Fecha de Ingreso: diciembre-2009
Mensajes: 85
Antigüedad: 14 años, 4 meses
Puntos: 0
Respuesta: Cambio de Clave en el Ldap

nada que ver colega, sale

DirectoryEntry
DirectorySearcher
SearchResultCollection

no estan definidos......

Etiquetas: clave, ldap, aspx, cambios
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 17:55.