User::Authenticate PHP Method

Authenticate() public method

public Authenticate ( )
    public function Authenticate()
    {
        $pass = false;
        $this->EncryptPassword();
        $users = getJSON('users.php');
        foreach ($users as $user) {
            if ($user['username'] == $this->username && $user['password'] == $this->password) {
                $pass = true;
                $_SESSION['user'] = $this->username;
                $_SESSION['lang'] = $this->lang;
                $_SESSION['theme'] = $this->theme;
                if ($user['project'] != '') {
                    $_SESSION['project'] = $user['project'];
                }
            }
        }
        if ($pass) {
            echo formatJSEND("success", array("username" => $this->username));
        } else {
            echo formatJSEND("error", "Incorrect Username or Password");
        }
    }

Usage Example

Example #1
0
 public function authenticate()
 {
     $data = array("username" => Input::get("username"), "password" => Input::get("password"));
     //
     $auth = new User();
     if ($auth->Authenticate($data)) {
         if (Auth::attempt($data)) {
             return Redirect::to('/')->with('message_login_success', 'Đăng nhập thành công!');
         } else {
             return Redirect::to('login')->withInput()->with('message_error', 'Mật khẩu không chính xác!');
         }
     } else {
         return Redirect::to('login')->withInput()->with('message_error', 'Tài khoản hoặc mật khẩu không chính xác!');
     }
 }
All Usage Examples Of User::Authenticate