Skip to content

Commit 6a5dfec

Browse files
committed
fixed auth bugs
1 parent 09d4128 commit 6a5dfec

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/core/auth.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,27 @@ public function basicLogin($username, $password, $password_encode = "md5") {
3636
"username" => "validusername",
3737
"password" => "required"
3838
]);
39+
if (!$this->select("users", "*", "username = ?", [$username])->fetchObj()) {
40+
$this->form->errorsArray["username"] = "Username doesn't exist";
41+
}
3942
if (!empty($this->form->errors())) {
4043
$this->response->respond([
4144
"errors" => $this->form->errors()
42-
]);
45+
]);
46+
exit();
4347
} else {
4448
if ($password_encode == "md5") {
4549
$password = md5($password);
4650
} else {
4751
$password = \base64_encode($password);
4852
}
4953
$user = $this->select("users", "*", "username = ? AND password = ?", [$username, $password])->fetchObj();
54+
if (!$user) {
55+
$this->response->respond([
56+
"errors" => "Password is incorrect"
57+
]);
58+
exit();
59+
}
5060
$token = $this->token->generateSimpleToken($user->id, "User secret key");
5161
$user->token = $token;
5262
unset($user->password);
@@ -62,13 +72,20 @@ public function basicRegister($username, $email, $password, $confirm_password, $
6272
"password" => "required",
6373
"confirm_password" => "required"
6474
]);
75+
if ($this->select("users", "*", "username = ?", [$username])->fetchObj()) {
76+
$this->form->errorsArray["username"] = "Username already exists";
77+
}
78+
if ($this->select("users", "*", "email = ?", [$email])->fetchObj()) {
79+
$this->form->errorsArray["email"] = "Email is already registered";
80+
}
6581
if ($password != $confirm_password) {
66-
$this->form->errors["password"] = "Your passwords don't match";
82+
$this->form->errorsArray["password"] = "Your passwords don't match";
6783
}
6884
if (!empty($this->form->errors())) {
6985
$this->response->respond([
7086
"errors" => $this->form->errors()
71-
]);
87+
]);
88+
exit();
7289
} else {
7390
if ($password_encode == "md5") {
7491
$password = md5($password);

src/core/db/mysqli.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ public function query(string $sql, array $params = [], string $types = ''): self
4141
exit();
4242
}
4343

44-
if(!is_array($params)) $params = [$params];
45-
4644
if(!$types) $types = str_repeat('s', count($params));
4745

4846
if(!$params) {

0 commit comments

Comments
 (0)