diff --git a/.htaccess b/.htaccess
index bde068d64b97cb25b854b470ba085e5d4c53fa9e..623837e28ee2189064826fa623a7b5aad26b442d 100644
--- a/.htaccess
+++ b/.htaccess
@@ -1,3 +1,5 @@
+Header add Access-Control-Allow-Origin: *
+
 RewriteEngine On
 RewriteBase /
 
diff --git a/api/apis/auth/login.php b/api/apis/auth/login.php
new file mode 100644
index 0000000000000000000000000000000000000000..a772c9d9c171507276d43fc843c320029573978d
--- /dev/null
+++ b/api/apis/auth/login.php
@@ -0,0 +1,29 @@
+<?php
+
+${basename(__FILE__, '.php')} = function(){
+    if($this->get_request_method() == "POST" and isset($this->_request['username']) and isset($this->_request['password'])){
+        $username = $this->_request['username'];
+        $password = $this->_request['password'];
+        try {
+            $auth = new Auth($username, $password);
+            $data = [
+                "message" => "Login success",
+                "token" => $auth->getAuthToken()
+            ];
+            $data = $this->json($data);
+            $this->response($data, 200);
+        } catch(Exception $e){
+            $data = [
+                "error" => $e->getMessage()
+            ];
+            $data = $this->json($data);
+            $this->response($data, 406);
+        }
+    } else {
+        $data = [
+            "error" => "Bad request"
+        ];
+        $data = $this->json($data);
+        $this->response($data, 400);
+    }
+};
\ No newline at end of file
diff --git a/api/apis/auth/signup.php b/api/apis/auth/signup.php
index fbfe8f5869395652003dda1a67aa6e672f27ce3b..99117d7ed298f7074ddc52e217a469b83224d39d 100644
--- a/api/apis/auth/signup.php
+++ b/api/apis/auth/signup.php
@@ -22,11 +22,7 @@ ${basename(__FILE__, '.php')} = function(){
          
     } else {
         $data = [
-            "error" => "Bad request",
-            "method" => $this->get_request_method(),
-            "server" => $_SERVER,
-            "post" => $_POST,
-            "get" => $_GET
+            "error" => "Bad request"
         ];
         $data = $this->json($data);
         $this->response($data, 400);
diff --git a/api/index.php b/api/index.php
index a9b03c750e73f22950c6326801f4f494a35ed741..124689a091df18f323984a4acfeef91e2f6d2346 100644
--- a/api/index.php
+++ b/api/index.php
@@ -3,6 +3,8 @@ error_reporting(E_ALL ^ E_DEPRECATED);
 require_once($_SERVER['DOCUMENT_ROOT']."/api/REST.api.php");
 require_once($_SERVER['DOCUMENT_ROOT']."/api/lib/Database.class.php");
 require_once($_SERVER['DOCUMENT_ROOT']."/api/lib/Signup.class.php");
+require_once($_SERVER['DOCUMENT_ROOT']."/api/lib/User.class.php");
+require_once($_SERVER['DOCUMENT_ROOT']."/api/lib/Auth.class.php");
 
 class API extends REST {
     
diff --git a/api/lib/Auth.class.php b/api/lib/Auth.class.php
index a4abe2dafcb3fabac023b6d4630c24fed41379c0..c9e5018be142620449ebaebda22b0c71294ce3d8 100644
--- a/api/lib/Auth.class.php
+++ b/api/lib/Auth.class.php
@@ -1,2 +1,61 @@
 <?php
 
+require_once($_SERVER['DOCUMENT_ROOT'].'/api/lib/Database.class.php');
+require_once($_SERVER['DOCUMENT_ROOT'].'/api/lib/User.class.php');
+require $_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php';
+
+class Auth {
+
+    private $db;
+    private $isTokenAuth = false;
+    private $loginToken = null;
+
+    public function __construct($username, $password = NULL){
+        $this->db = Database::getConnection();
+        if($password == NULL){
+            //token based auth
+            $this->token = $username;
+            $this->isTokenAuth = true;
+            //we have to validate the token
+        } else {
+            $this->username = $username; //it might be username or email.
+            $this->password = $password;
+        }
+
+        if($this->isTokenAuth){
+            throw new Exception("Not Implemented");
+        } else {
+            $user = new User($this->username);
+            $hash = $user->getPasswordHash();
+            $this->username = $user->getUsername();
+            if(password_verify($this->password, $hash)){
+                if(!$user->isActive()){
+                    throw new Exception("Please check your email and activate your account.");
+                }
+                $this->loginToken = $this->addSession();
+            } else {
+                throw new Exception("Password Mismatch");
+            }
+        }
+    }
+
+    public function getAuthToken(){
+        return $this->loginToken;
+    }
+
+    private function addSession(){
+        $token = Auth::generateRandomHash(32);
+        $query = "INSERT INTO `apis`.`session` (`username`, `token`) VALUES ('$this->username', '$token');";
+        if(mysqli_query($this->db, $query)){
+            return $token;
+        } else {
+            throw new Exception(mysqli_error($this->db));
+        }
+        
+    }
+
+    public static function generateRandomHash($len){
+        $bytes = openssl_random_pseudo_bytes($len, $cstrong);
+        return bin2hex($bytes);
+    }
+}
\ No newline at end of file
diff --git a/api/lib/User.class.php b/api/lib/User.class.php
new file mode 100644
index 0000000000000000000000000000000000000000..01be1f28475110eec54492dd23d8d58fa2731206
--- /dev/null
+++ b/api/lib/User.class.php
@@ -0,0 +1,38 @@
+<?php
+
+require_once($_SERVER['DOCUMENT_ROOT'].'/api/lib/Database.class.php');
+require $_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php';
+
+class User {
+    private $db;
+    private $user;
+
+    public function __construct($username){
+        $this->username = $username;
+        $this->db = Database::getConnection();
+        $query = "SELECT * FROM auth WHERE username='$this->username' OR email='$this->username'";
+        //echo $query;
+        $result = mysqli_query($this->db, $query);
+        if(mysqli_num_rows($result) == 1){
+            $this->user = mysqli_fetch_assoc($result);
+        } else {
+            throw new Exception("User not found");
+        }
+    }
+
+    public function getUsername(){
+        return $this->user['username'];
+    }
+
+    public function getPasswordHash(){
+        return $this->user['password'];
+    }
+
+    public function getEmail(){
+        return $this->user['email'];
+    }
+
+    public function isActive(){
+        return $this->user['active'];
+    }
+}
\ No newline at end of file
diff --git a/hash.php b/hash.php
new file mode 100644
index 0000000000000000000000000000000000000000..fc8cb10028e718b886962854208a968a8108b0c3
--- /dev/null
+++ b/hash.php
@@ -0,0 +1,9 @@
+<?php
+
+    $bytes = openssl_random_pseudo_bytes(32, $cstrong);
+    $hex   = bin2hex($bytes);
+    echo "Lengths: Bytes: $i and Hex: " . strlen($hex) . PHP_EOL;
+    var_dump($hex);
+    var_dump($cstrong);
+    echo PHP_EOL;
+?>
\ No newline at end of file
diff --git a/sg.php b/sg.php
index 5a6a525fdd18b6fd67e3f55005cd65d078388ed9..de13316e8fdfd7494b6d79ff24f6bbdc5d1d1a0a 100644
--- a/sg.php
+++ b/sg.php
@@ -1,14 +1,15 @@
 <pre>
 <?php
+require $_SERVER['DOCUMENT_ROOT'].'/vendor/autoload.php';
+require_once($_SERVER['DOCUMENT_ROOT'].'/api/lib/User.class.php');
+
+try{
+    $user = new User('sibidharan@icloud.com');
+    echo $user->getUsername();
+} catch(Exception $e){
+    echo $e->getMessage();
+}
 
-print_r($GLOBALS);
-print_r($_SERVER);
-print_r($_REQUEST);
-print_r($_POST);
-print_r($_GET);
-print_r($_FILES);
-print_r($_ENV);
-print_r($_COOKIE);
 
 ?>
 </pre>
\ No newline at end of file