I'm writing an application that depends on a LDAP login. When a user logs into the system with their valid LDAP credentials, an API token is granted to be used to interact with the application from that point on (API-driven web app). However, the application needs to be setup so that whenever a user is deleted from the LDAP server, the API keys are revoked as well. My plan is to setup a cronjob to periodically check if the LDAP credentials are still valid. Therefore, I'd need to save these credentials so that I can check them later. I realized though, that this would mean that I'd have to save the passwords the users provide as plain text, otherwise I would not be able to send them to the LDAP server for verification.
I'm personally not very experienced with LDAP, so I was wondering if there is any way around this. I thought about storing the hashes of the passwords, and wondered if it was somehow possible to verify the credentials by using the hash of the password instead of the password itself, but then quickly realised that this would not really be any safer, because if the database would be compromised, it does not really matter if the passwords are hashed or not if they can both be used to authenticate. The only benefit of that would be that it might be harder to check if the user uses the same password for other services.
All suggestions are appreciated. Thanks!