-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathldap.php
63 lines (56 loc) · 1.29 KB
/
ldap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
session_start();
error_reporting(0);
$server_address = "";
function chk_user( $uid, $pwd ) {
if ($pwd) {
$ds = ldap_connect($server_address);
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$a = ldap_search($ds, "dc=iiita,dc=ac,dc=in", "uid=$uid" );
$b = ldap_get_entries( $ds, $a );
$dn = $b[0]["dn"];
$ldapbind=@ldap_bind($ds, $dn, $pwd);
if ($ldapbind) {
return 1;
} else {
return 0;
}
ldap_close($ds);
} else {
return 0;
}
}
function get_name($uid) {
$ds=ldap_connect($server_adress);
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
if ($ds)
{
$bnd=ldap_bind($ds);
$srch=ldap_search($ds, "dc=iiita,dc=ac,dc=in", "uid={$uid}");
$info=ldap_get_entries($ds, $srch);
ldap_close($ds);
$userdn=$info[0]["dn"];
$usernm=$info[0]["cn"][0];
return $info[0]["cn"][0];
} else {
return "Not available";
}
}
$true=chk_user($user, $pass);
$data = "";
if($true){
$name=get_name($user);
$arr = explode("-",$name);
$fname1=substr($name, 0, strrpos($name, "-"));
$fname=str_replace("-", " ", $fname1);
$_SESSION['name']=$name;
$_SESSION['fname']=$fname;
$_SESSION['user']=$user;
$new="";
$data = $user;
}
else{
$data = "invalid credentials";
}
echo $data;
?>