PHP User authentic with LDAP

2011 January 3 at 3:33 pm Leave a comment

Jika dalam suatu perusahaan memiliki banyak aplikasi, apa yang akan dirasakan para user?  Emmm… mudah ditebak mereka para user akan kesulitan mengingat user dan password dari masing-masing aplikasi, dan para administrator aplikasi akan disibukan memenage banyak database user Beruntung ada LDAP(Lightweight Directory Access Protocol) yang bisa membaca AD System. Sehingga user/password aplikasi akan sama dengan user/password Operating system. Berikut cuplikan code

<?php

$username=””;
$password=””;
$bind_user=false;

if($_POST){

$port=”389″;
$server=”server_LDAP_Name”;
$ldap_version=3;
$ldap_ref=0;
$base_dn=”dc=mydomain; dc=co; dc=id”;#ex: mydomain.co.id

$username=$_POST[‘user_name’];
$password=$_POST[‘pwd’];

$rs = @ldap_connect($server,$port);
@ldap_set_option($rs, LDAP_OPT_PROTOCOL_VERSION, $ldap_version);
@ldap_set_option($rs, LDAP_OPT_REFERRALS, $ldap_ref);
$result = @ldap_search($rs, $base_dn,”(sAMAccountName={$username})”);
$result_user = @ldap_get_entries($rs, $result);
if($result_user[“count”] ==1 ){

$first_user = $result_user[0];
$ldap_user_dn = $first_user[“dn”];
$bind_user = @ldap_bind($rs, $ldap_user_dn, $password);
if ($bind_user)$success=true;

#print_r($result_user);

}

if($success)echo “Sucess”;
else echo “Invalid User / Password”;
@ldap_close($rs);

}?>
<form method=post>
<table>
<tr><td>user Name <td>:<td><input type=text name=user_name value=”<? echo $username ?>”>
<tr><td>password <td>:<td><input type=password name=pwd value=”<? echo $password ?>”>
<tr><td><input type=submit value=”Click Here to Test”>
</table>
</form>

Entry filed under: PHP. Tags: .

Install php 5 mssql di server ubuntu Basic Photographi

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Trackback this post  |  Subscribe to the comments via RSS Feed


Categories


%d bloggers like this: