How to authenticate via LDAP
$ldapServer = 'ldap://ldap_server.domain.me';
$ldapPort = 389;
$ldapBaseDn = 'cn=users,dc=ldap_server,dc=domain,dc=me'; // Replace with your base DN
// User provided credentials
$username = 'username';
$password = 'password@123';
// Connect to the LDAP server
$ldapConn = ldap_connect($ldapServer, $ldapPort);
if (!$ldapConn) {
echo "Failed to connect to the LDAP server";
exit;
}
// Set LDAP options
ldap_set_option($ldapConn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapConn, LDAP_OPT_REFERRALS, 0);
// Bind with the provided username and password
$ldapBind = @ldap_bind($ldapConn, "uid=$username,$ldapBaseDn", $password);
// Check if the bind was successful
if ($ldapBind) {
echo "Authentication successful!";
// Perform any further actions or grant access to the application
} else {
echo "Authentication failed.";
}
ldap_unbind($ldapConn);
0
Howdy, Stranger!
Categories
- 99 All Categories
- 24 VoIP
- 11 SIP
- 16 asterisk
- 44 Programming
- 1 Nodejs
- 4 javascript
- 19 PHP
- 8 Codeigniter
- 14 database
- 1 UI/UX
- 2 Flutter
- 29 OS
- 27 Linux
- 1 Virtualization
- 1 Android
- 1 Windows
- 2 legal
