Skip to content

Commit

Permalink
fixed auth bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
mychidarko committed Dec 11, 2019
1 parent 09d4128 commit 6a5dfec
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 20 additions & 3 deletions src/core/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,27 @@ public function basicLogin($username, $password, $password_encode = "md5") {
"username" => "validusername",
"password" => "required"
]);
if (!$this->select("users", "*", "username = ?", [$username])->fetchObj()) {
$this->form->errorsArray["username"] = "Username doesn't exist";
}
if (!empty($this->form->errors())) {
$this->response->respond([
"errors" => $this->form->errors()
]);
]);
exit();
} else {
if ($password_encode == "md5") {
$password = md5($password);
} else {
$password = \base64_encode($password);
}
$user = $this->select("users", "*", "username = ? AND password = ?", [$username, $password])->fetchObj();
if (!$user) {
$this->response->respond([
"errors" => "Password is incorrect"
]);
exit();
}
$token = $this->token->generateSimpleToken($user->id, "User secret key");
$user->token = $token;
unset($user->password);
Expand All @@ -62,13 +72,20 @@ public function basicRegister($username, $email, $password, $confirm_password, $
"password" => "required",
"confirm_password" => "required"
]);
if ($this->select("users", "*", "username = ?", [$username])->fetchObj()) {
$this->form->errorsArray["username"] = "Username already exists";
}
if ($this->select("users", "*", "email = ?", [$email])->fetchObj()) {
$this->form->errorsArray["email"] = "Email is already registered";
}
if ($password != $confirm_password) {
$this->form->errors["password"] = "Your passwords don't match";
$this->form->errorsArray["password"] = "Your passwords don't match";
}
if (!empty($this->form->errors())) {
$this->response->respond([
"errors" => $this->form->errors()
]);
]);
exit();
} else {
if ($password_encode == "md5") {
$password = md5($password);
Expand Down
2 changes: 0 additions & 2 deletions src/core/db/mysqli.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public function query(string $sql, array $params = [], string $types = ''): self
exit();
}

if(!is_array($params)) $params = [$params];

if(!$types) $types = str_repeat('s', count($params));

if(!$params) {
Expand Down

0 comments on commit 6a5dfec

Please sign in to comment.