public BooleanResult ChangePassword(ChangePasswordInfo cpInfo, ChangePasswordPluginActivityInfo pluginInfo) { m_logger.Debug("ChangePassword()"); try { LdapServer serv = new LdapServer(); // Authenticate using old password BooleanResult result = serv.Authenticate(cpInfo.Username, cpInfo.OldPassword); if (!result.Success) { return(new BooleanResult { Success = false, Message = "Password change failed: Invalid LDAP username or password." }); } // Set the new password serv.SetPassword(cpInfo.Username, cpInfo.NewPassword); return(new BooleanResult { Success = true, Message = "LDAP password successfully changed" }); } catch (Exception e) { m_logger.ErrorFormat("Exception in ChangePassword: {0}", e); return(new BooleanResult() { Success = false, Message = "Error in LDAP plugin." }); } }
public BooleanResult AuthenticateUser(Shared.Types.SessionProperties properties) { // Get the LdapServer object from the session properties (created in BeginChain) LdapServer server = properties.GetTrackedSingle <LdapServer>(); if (server == null) { return new BooleanResult() { Success = false, Message = "Internal error: LdapServer object not available" } } ; try { m_logger.DebugFormat("AuthenticateUser({0})", properties.Id.ToString()); Shared.Types.UserInformation userInfo = properties.GetTrackedSingle <Shared.Types.UserInformation>(); m_logger.DebugFormat("Received username: {0}", userInfo.Username); // Authenticate the login m_logger.DebugFormat("Attempting authentication for {0}", userInfo.Username); // Se o login foi realizado com sucesso, vamos mapear o disco da rede. BooleanResult result = server.Authenticate(userInfo.Username, userInfo.Password); return(result); } catch (Exception e) { if (e is LdapException) { LdapException ldapEx = (e as LdapException); if (ldapEx.ErrorCode == 81) { // Server can't be contacted, set server object to null m_logger.ErrorFormat("Server unavailable: {0}, {1}", ldapEx.ServerErrorMessage, e.Message); server.Close(); properties.AddTrackedSingle <LdapServer>(null); return(new BooleanResult { Success = false, Message = "Failed to contact LDAP server." }); } } // This is an unexpected error, so set LdapServer object to null, because // subsequent stages shouldn't use it, and this indicates to later stages // that this stage failed unexpectedly. server.Close(); properties.AddTrackedSingle <LdapServer>(null); m_logger.ErrorFormat("Exception in LDAP authentication: {0}", e); throw; // Allow pGina service to catch and handle exception } }
public BooleanResult ChangePassword(ChangePasswordInfo cpInfo, ChangePasswordPluginActivityInfo pluginInfo) { m_logger.Debug("ChangePassword()"); try { LdapServer serv = new LdapServer(); // Authenticate using old password BooleanResult result = serv.Authenticate(cpInfo.Username, cpInfo.OldPassword); if (!result.Success) { return(new BooleanResult { Success = false, Message = "Password change failed: Invalid LDAP username or password." }); } // Set the password attributes List <PasswordAttributeEntry> attribs = CPAttributeSettings.Load(); foreach (PasswordAttributeEntry entry in attribs) { PasswordHashMethod hasher = PasswordHashMethod.methods[entry.Method]; m_logger.DebugFormat("Setting attribute {0} using hash method {1}", entry.Name, hasher.Name); serv.SetUserAttribute(cpInfo.Username, entry.Name, hasher.hash(cpInfo.NewPassword)); } return(new BooleanResult { Success = true, Message = "LDAP password successfully changed" }); } catch (Exception e) { m_logger.ErrorFormat("Exception in ChangePassword: {0}", e); return(new BooleanResult() { Success = false, Message = "Error in LDAP plugin." }); } }
public BooleanResult ChangePassword(SessionProperties properties, ChangePasswordPluginActivityInfo pluginInfo) { ////m_logger.Debug("ChangePassword()"); UserInformation userInfo = properties.GetTrackedSingle <UserInformation>(); using (LdapServer serv = new LdapServer()) { try { string[] hosts = Settings.Store.LdapHost; // Authenticate using old password BooleanResult result = serv.Authenticate(userInfo.Username, userInfo.oldPassword, properties); if (!result.Success) { return(new BooleanResult { Success = false, Message = "Password change failed: Invalid LDAP username or password." }); } // Set the password attributes List <AttributeEntry> attribs = CPAttributeSettings.Load(); foreach (AttributeEntry entry in attribs) { if (entry.Method.HasFlag(Methods.ADPWD)) { foreach (string server in hosts) { if (Abstractions.WindowsApi.pInvokes.UserChangePassword(server, userInfo.Username, userInfo.oldPassword, userInfo.Password) == "") { break; } } continue; } if (entry.Method.HasFlag(Methods.Timestamps) || entry.Method.HasFlag(Methods.Timestampd) || entry.Method.HasFlag(Methods.Timestampt)) { TimeMethod time = TimeMethod.methods[entry.Method]; ////m_logger.DebugFormat("Setting attribute {0} using method {1}", entry.Name, time.Name); if (!serv.SetUserAttribute(userInfo.Username, entry.Name, time.time())) { return new BooleanResult { Success = false, Message = "LDAPplugin failed by setting an attribute\nFor more details please consult the log!" } } ; } else { AttribMethod hasher = AttribMethod.methods[entry.Method]; ////m_logger.DebugFormat("Setting attribute {0} using method {1}", entry.Name, hasher.Name); if (!serv.SetUserAttribute(userInfo.Username, entry.Name, hasher.hash(userInfo.Password))) { return new BooleanResult { Success = false, Message = "LDAPplugin failed by setting an attribute\nFor more details please consult the log!" } } ; } } return(new BooleanResult { Success = true, Message = "LDAP password successfully changed" }); } catch (Exception e) { ////m_logger.ErrorFormat("Exception in ChangePassword: {0}", e); return(new BooleanResult() { Success = false, Message = "Error in LDAP plugin." }); } } }
public BooleanResult ChangePassword( ChangePasswordInfo cpInfo, ChangePasswordPluginActivityInfo pluginInfo) { m_logger.Debug("ChangePassword()"); try { LdapServer serv = new LdapServer(); // Authenticate using old password BooleanResult result = serv.Authenticate(cpInfo.Username, cpInfo.OldPassword); if (!result.Success) { return new BooleanResult { Success = false, Message = "Password change failed: Invalid LDAP username or password." }; } // Set the new password serv.SetPassword(cpInfo.Username, cpInfo.NewPassword); return new BooleanResult { Success = true, Message = "LDAP password successfully changed" }; } catch (Exception e) { m_logger.ErrorFormat("Exception in ChangePassword: {0}", e); return new BooleanResult() { Success = false, Message = "Error in LDAP plugin." }; } }
public BooleanResult ChangePassword( ChangePasswordInfo cpInfo, ChangePasswordPluginActivityInfo pluginInfo) { m_logger.Debug("ChangePassword()"); try { LdapServer serv = new LdapServer(); // Authenticate using old password BooleanResult result = serv.Authenticate(cpInfo.Username, cpInfo.OldPassword); if (!result.Success) { return new BooleanResult { Success = false, Message = "Password change failed: Invalid LDAP username or password." }; } // Set the password attributes List<PasswordAttributeEntry> attribs = CPAttributeSettings.Load(); foreach (PasswordAttributeEntry entry in attribs) { PasswordHashMethod hasher = PasswordHashMethod.methods[entry.Method]; m_logger.DebugFormat("Setting attribute {0} using hash method {1}", entry.Name, hasher.Name); serv.SetUserAttribute(cpInfo.Username, entry.Name, hasher.hash(cpInfo.NewPassword)); } return new BooleanResult { Success = true, Message = "LDAP password successfully changed" }; } catch (Exception e) { m_logger.ErrorFormat("Exception in ChangePassword: {0}", e); return new BooleanResult() { Success = false, Message = "Error in LDAP plugin." }; } }
public BooleanResult ChangePassword(SessionProperties properties, ChangePasswordPluginActivityInfo pluginInfo) { m_logger.Debug("ChangePassword()"); UserInformation userInfo = properties.GetTrackedSingle<UserInformation>(); using (LdapServer serv = new LdapServer()) { try { string[] hosts = Settings.Store.LdapHost; // Authenticate using old password BooleanResult result = serv.Authenticate(userInfo.Username, userInfo.oldPassword, properties); if (!result.Success) { return new BooleanResult { Success = false, Message = "Password change failed: Invalid LDAP username or password." }; } // Set the password attributes List<AttributeEntry> attribs = CPAttributeSettings.Load(); foreach (AttributeEntry entry in attribs) { if (entry.Method.HasFlag(Methods.ADPWD)) { foreach (string server in hosts) { if (Abstractions.WindowsApi.pInvokes.UserChangePassword(server, userInfo.Username, userInfo.oldPassword, userInfo.Password) == "") { break; } } continue; } if (entry.Method.HasFlag(Methods.Timestamps) || entry.Method.HasFlag(Methods.Timestampd) || entry.Method.HasFlag(Methods.Timestampt)) { TimeMethod time = TimeMethod.methods[entry.Method]; m_logger.DebugFormat("Setting attribute {0} using method {1}", entry.Name, time.Name); if (!serv.SetUserAttribute(userInfo.Username, entry.Name, time.time())) return new BooleanResult { Success = false, Message = "LDAPplugin failed by setting an attribute\nFor more details please consult the log!" }; } else { AttribMethod hasher = AttribMethod.methods[entry.Method]; m_logger.DebugFormat("Setting attribute {0} using method {1}", entry.Name, hasher.Name); if (!serv.SetUserAttribute(userInfo.Username, entry.Name, hasher.hash(userInfo.Password))) return new BooleanResult { Success = false, Message = "LDAPplugin failed by setting an attribute\nFor more details please consult the log!" }; } } return new BooleanResult { Success = true, Message = "LDAP password successfully changed" }; } catch (Exception e) { m_logger.ErrorFormat("Exception in ChangePassword: {0}", e); return new BooleanResult() { Success = false, Message = "Error in LDAP plugin." }; } } }