Skip to content

Commit

Permalink
Added error handling, multiple user handling, sess
Browse files Browse the repository at this point in the history
  • Loading branch information
sweep-ai[bot] committed Aug 22, 2023
1 parent 487faa4 commit f7b7126
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion application/controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,21 @@ public function admin_login($username, $password) {

// Check the credentials against the users table in the database
$user = $this->UserModel->get_user_by_username($username);
if ($user && password_verify($password, $user['password'])) {
if ($user === false) {
// The get_user_by_username function failed
return array('status' => 'error', 'message' => 'An error occurred');
} elseif (count($user) > 1) {
// Multiple users with the same username exist in the database
return array('status' => 'error', 'message' => 'Multiple users with the same username exist');
} elseif (password_verify($password, $user['password'])) {
// The credentials are correct
// Set a session variable with the user's id
$this->session->set_userdata('user_id', $user['id']);
return array('status' => 'success', 'message' => 'Login successful');
} else {
// The credentials are incorrect
// Log the unsuccessful login attempt
$this->log_unsuccessful_login_attempt($username);
return array('status' => 'error', 'message' => 'Invalid username or password');
}
}
Expand Down

0 comments on commit f7b7126

Please sign in to comment.