Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private function dologinWithPostData()
- {
- if (empty($_POST['user_name'])) {
- $this->errors[] = "Username field was empty.";
- } elseif (empty($_POST['user_password'])) {
- $this->errors[] = "Password field was empty.";
- } elseif (!empty($_POST['user_name']) && !empty($_POST['user_password'])) {
- //ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
- $username = $_POST['user_name'];
- $password = $_POST['user_password'];
- $adServer = "ldaps://The Address";
- $ldap = ldap_connect($adServer);
- $ldaprdn = 'MYDN.net' . "\" . $username;
- ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
- ldap_set_option($ldap, LDAP_OPT_REFERRALS, 0);
- $bind = @ldap_bind($ldap, $ldaprdn, $password);
- if ($bind) {
- // Get user info by there account login
- $filter="(sAMAccountName=$username)";
- $result = ldap_search($ldap,"dc=MYDC,dc=NET",$filter);
- ldap_sort($ldap,$result,"sn");
- $info = ldap_get_entries($ldap, $result);
- @ldap_close($ldap);
- $fullName = $info[0]["displayname"][0];
- $dn = $info[0]["dn"];
- $groups = array();
- if (array_key_exists("memberof", $info[0])){
- $x = $info[0]["memberof"];
- $groups = array();
- foreach ($x as $key){
- if(strlen($key)>1){
- array_push($groups, $this->get_string_between($key, "CN=", ",") );
- }
- }
- }
- @ldap_close($ldap);
- $_SESSION['userID'] = bin2hex($info[0]["objectguid"][0]);
- $_SESSION['fullName'] = $fullName;
- $_SESSION['userGroups'] = $groups;
- $_SESSION['loggedOnStatus'] = "1";
- if(in_array('Dept_Directors', $groups)){
- $_SESSION['userLevel'] = 10;
- }elseif(in_array('Dept_Admin', $groups)){
- $_SESSION['userLevel'] = 7;
- }else{
- $_SESSION['userLevel'] = 0;
- }
- if (strpos($dn, 'OU=MYOU') !== false) {
- $_SESSION['userType'] = 2;
- }elseif(strpos($dn, 'OU=MYOU') !== false){
- $_SESSION['userType'] = 1;
- }
- if($this->checkUserProfileExsists() == false){
- if(!($this->createUserProfile())){
- $msg="Error Creating User Profile ";
- echo $msg;
- }
- }
- } else {
- @ldap_close($ldap);
- $this->errors[] = "Wrong Username or Password";
- }
- } else {
- @ldap_close($ldap);
- echo "Wrong password. Try again.";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement