diff --git a/src/api/composer.json b/src/api/composer.json
index 39ee7f1..582bc48 100644
--- a/src/api/composer.json
+++ b/src/api/composer.json
@@ -19,5 +19,6 @@
],
"autoload": {
"classmap": [ "controllers", "models" ]
- }
+ },
+ "minimum-stability": "stable"
}
diff --git a/src/api/controllers/Auth.php b/src/api/controllers/Auth.php
index 77cb8ed..2237c25 100644
--- a/src/api/controllers/Auth.php
+++ b/src/api/controllers/Auth.php
@@ -3,17 +3,18 @@ use RedBeanPHP\R;
use Firebase\JWT;
class Auth extends BaseController {
- public function authenticate($request, $response, $args) {
- if (!$request->hasHeader('Authorization') {
- $apiJson = new ApiJson();
+ public function authenticate($request, $response, $args) {
+ if (!$request->hasHeader('Authorization')) {
return $response->withStatus(400); // Bad Request
}
- $jwt = $response->getHeader('Authorization');
+ $jwt = $request->getHeader('Authorization');
// Validate token
// Issue new token with extended expiration
+
+ return $response->withJson(json_encode($jwt));
}
public function login($request, $response, $args) {
@@ -26,7 +27,7 @@ class Auth extends BaseController {
return $this->jsonResponse($response);
}
- if ($user->password !== $this->hashPassword($data->password, $user->salt) {
+ if (!password_verify($data->password, $user->password_hash)) {
$this->apiJson->addAlert('error', 'Invalid username or password.');
return $this->jsonResponse($response);
@@ -43,16 +44,15 @@ class Auth extends BaseController {
$key = R::load('jwt', 1);
if ($key->id === 0) {
+ // Generate a JWT key by hashing the current time.
+ // This should make (effectively) every instance of TaskBoard
+ // have a unique secret key for JWTs.
$key->token = password_hash(strval(time()), PASSWORD_BCRYPT);
+
R::store($key);
}
return $key->token;
}
-
- private function hashPassword($password, $salt) {
- return password_hash($data->password, PASSWORD_BCRYPT,
- array('salt' => $salt));
- }
}
diff --git a/src/api/models/User.php b/src/api/models/User.php
index 1238771..59fa079 100644
--- a/src/api/models/User.php
+++ b/src/api/models/User.php
@@ -11,7 +11,6 @@ class User extends BaseModel {
public $id = 0;
public $security_level;
public $username = '';
- public $salt = '';
public $password_hash = '';
public $email = '';
public $default_board_id = 0;
@@ -32,7 +31,6 @@ class User extends BaseModel {
$bean->id = $this->id;
$bean->security_level = $this->security_level->getValue();
$bean->username = $this->username;
- $bean->salt = $this->salt;
$bean->password_hash = $this->password_hash;
$bean->email = $this->email;
$bean->default_board_id = $this->default_board_id;
@@ -73,7 +71,6 @@ class User extends BaseModel {
$this->id = (int) $obj->id;
$this->security_level = new SecurityLevel((int) $obj->security_level);
$this->username = $obj->username;
- $this->salt = $obj->salt;
$this->password_hash = $obj->password_hash;
$this->email = $obj->email;
$this->default_board_id = (int) $obj->default_board_id;
diff --git a/src/app/settings/settings.template.html b/src/app/settings/settings.template.html
index c6ef5bf..ad18fb7 100644
--- a/src/app/settings/settings.template.html
+++ b/src/app/settings/settings.template.html
@@ -18,12 +18,13 @@
-
Select Default Board
-
-
- All Boards Options
+ All Boards Options
+