}
                             }
                         }
                     }
                 }
             }
         }
     } else {
         // Not valid login
         Session::destroy();
         $validate->addError('Wrong Username or Password');
     }
 } else {
     $email = Input::get('a') . '@student.nits.ac.in';
     $ldap = new LDAP();
     if ($ldap->Auth($email, Input::get('b')) && Token::check(Input::get('token'))) {
         // verify using LDAP and check token!!
         if (Session::get('type') === 'faculty') {
             //check who logged in, differentiating between student and faculty members' login!
             //case for teacher's or other staff's login
             $validate->addError("Please <a href='http://mis.nits.ac.in'>CLICK HERE</a> for faculty login area.");
             Session::destroy();
         } else {
             if (Session::get('type') === 'student') {
                 // case for students' login!!
                 $student = new Student();
                 $v = $student->validateLogin();
                 if ($v == 1) {
                     $cookiename = 'sisnootp' . $student->getMobile();
                     if (1) {
                         //Cookie::get($cookiename)
if (loggedIn()) {
    Redirect::to('home.php');
    exit;
}
if (Input::exists()) {
    if (Input::get('login') != '') {
        $validate = new Validate();
        $validation = $validate->check($_POST, array('a' => array('required' => true), 'b' => array('required' => true), 'g-recaptcha-response' => array('required' => true)));
        if ($validate->passed()) {
            $captcha_check = new Recaptcha();
            $ver = $captcha_check->verifyResponse();
            if ($ver->success) {
                //verify captcha
                if (validateEmail(Input::get('a'))) {
                    $ldap = new LDAP();
                    if ($ldap->Auth(Input::get('a'), Input::get('b')) && Token::check(Input::get('token'))) {
                        // verify using LDAP and check token!!
                        if (Session::get('type') === 'faculty') {
                            //check who logged in, differentiating between student and faculty members' login!
                            //case for teacher's or other staff's login
                            $teacher = new Teacher();
                            $v = $teacher->validateLogin(Input::get('a'));
                            if ($v == 1) {
                                $cookiename = 'misnootp' . $teacher->getMobile();
                                if (1) {
                                    Session::put('loggedIn', 1);
                                    $log = new Log();
                                    $log->loginLog('success');
                                    Redirect::to('home.php');
                                } else {
                                    $otp = new OTP();
 public function changeMobile($teacher_id, $mobile)
 {
     $l = new LDAP();
     if (!loggedIn() || $l->Auth(Session::get('teacher_email'), Input::get('cpwd')) != 1) {
         return 3;
     }
     $this->_connect();
     $teacher_id = $this->_db->real_escape_string(escape($teacher_id));
     $mobile = $this->_db->real_escape_string(escape($mobile));
     $query = "UPDATE teachers SET mobile = '" . $mobile . "' WHERE teacher_id='" . $teacher_id . "'";
     $result = $this->_db->query($query);
     if ($this->_db->error == '') {
         if ($this->_db->affected_rows) {
             return 1;
         } else {
             return 2;
         }
     } else {
         return 0;
     }
 }
 public function changeMobile($scholar_no, $mobile)
 {
     $l = new LDAP();
     if (!loggedIn() || $l->Auth(Session::get('student_email'), Input::get('cpwd')) != 1) {
         return 3;
     }
     $this->_connect();
     $scholar_no = $this->_db->real_escape_string(escape($scholar_no));
     $mobile = $this->_db->real_escape_string(escape($mobile));
     $query = "UPDATE students_info SET mobile = '" . $mobile . "' WHERE scholar_no='" . $scholar_no . "'";
     $result = $this->_db->query($query);
     if ($this->_db->error == '') {
         if ($this->_db->affected_rows) {
             return 1;
         } else {
             return 2;
         }
     } else {
         return 0;
     }
 }
<?php

require_once '../core/init.php';
if (Input::exists('post') && privilege() != NULL) {
    $validate = new Validate();
    $validation = $validate->check($_POST, array('cpwd' => array('required' => true), 'newpwd1' => array('required' => true, 'min' => 6, 'matches' => 'newpwd2')));
    if ($validate->passed()) {
        $ldap = new LDAP();
        if (!loggedIn() || $ldap->Auth(Session::get('teacher_email'), Input::get('cpwd')) != 1) {
            echo '<div class="alert alert-danger alert-dismissible" role="alert">';
            echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
            echo 'Invalid authentication. Please enter correct password or re-login.';
            echo '</div>';
            die;
        } else {
            $add = $ldap->changePassword(Session::get('teacher_email'), Input::get('newpwd1'));
            if ($add == 1) {
                echo '<div class="alert alert-success alert-dismissible" role="alert">';
                echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
                echo 'Password changed successfully';
                echo '</div>';
            } else {
                if ($add == 0) {
                    echo '<div class="alert alert-danger alert-dismissible" role="alert">';
                    echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
                    echo 'Temporary Error';
                    echo '</div>';
                }
            }
        }
    } else {
<?php

require_once '../../core/init.php';
if (Input::exists('post')) {
    $validate = new Validate();
    $validation = $validate->check($_POST, array('cpwd' => array('required' => true), 'newpwd1' => array('required' => true, 'min' => 6, 'matches' => 'newpwd2')));
    if ($validate->passed()) {
        $ldap = new LDAP();
        if (!loggedIn() || $ldap->Auth(Session::get('student_email'), Input::get('cpwd')) != 1) {
            echo '<div class="alert alert-danger alert-dismissible" role="alert">';
            echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
            echo 'Invalid authentication. Please enter correct password or re-login.';
            echo '</div>';
        }
        $add = $ldap->changePassword(Session::get('student_email'), Input::get('newpwd1'));
        if ($add == 1) {
            echo '<div class="alert alert-success alert-dismissible" role="alert">';
            echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
            echo 'Password changed successfully';
            echo '</div>';
        } else {
            if ($add == 0) {
                echo '<div class="alert alert-danger alert-dismissible" role="alert">';
                echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
                echo 'Temporary Error';
                echo '</div>';
            }
        }
    } else {
        echo '<div class="alert alert-warning alert-dismissible" role="alert">';
        echo '<button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';