public function login($username, $password) { $loginAttempts = new LoginAttempts($this->db, $this); $loginAttempts->check(); $sth = $this->db->prepare('SELECT * FROM users WHERE username = ?'); $sth->bindParam(1, $username, PDO::PARAM_STR, 15); $sth->execute(); if ($arr = $sth->fetch(PDO::FETCH_ASSOC)) { if (password_verify($password . User::PASSWORD_SALT, $arr["passhash"])) { if ($arr["enabled"] == "no") { $loginAttempts->create(array("username" => $username, "password" => $password, "uid" => $arr["id"])); throw new Exception(L::get("USER_DISABLED", [$arr["secret"]]), 401); } setcookie("uid", $arr["id"], time() + 31556926, "/"); setcookie("pass", $this->hashCookie($arr["passhash"], $arr["class"] >= User::CLASS_VIP), time() + 31556926, "/"); $this->setPrivateVars($arr); } else { $loginAttempts->create(array("username" => $username, "password" => $password, "uid" => $arr["id"])); throw new Exception(L::get("USER_WRONG_CREDENTIALS"), 401); } } else { $loginAttempts->create(array("username" => $username, "password" => $password)); throw new Exception(L::get("USER_WRONG_CREDENTIALS"), 401); } }
public function login($username, $password) { $loginAttempts = new LoginAttempts($this->db, $this); $loginAttempts->check(); $sth = $this->db->prepare('SELECT * FROM users WHERE username = ?'); $sth->bindParam(1, $username, PDO::PARAM_STR, 15); $sth->execute(); if ($arr = $sth->fetch(PDO::FETCH_ASSOC)) { if ($arr["passhash"] == $this->hashPassword($password, $arr["added"])) { if ($arr["enabled"] == "no") { if ($arr["uploaded"] / $arr["downloaded"] > 0.5 && !strpos($arr["modcomment"], 'Disabled by') && !strpos($arr["modcomment"], 'Kontot inaktiverat utav')) { $this->db->query("UPDATE users SET enabled = 'yes' WHERE id = " . $arr["id"]); } else { $loginAttempts->create(array("username" => $username, "password" => $password, "uid" => $arr["id"])); throw new Exception('Användarkontot är avstängt med anledningen: ' . $arr["secret"], 401); } } setcookie("uid", $arr["id"], time() + 31556926, "/"); if ($arr["class"] >= 7) { $hashWithIp = "true"; setcookie("notuseip", "true", time() + 315569260, "/"); } setcookie("pass", $this->hashCookie($arr["passhash"], $arr["class"] >= 7), time() + 31556926, "/"); if ($arr["class"] >= 8) { setcookie("admin", md5($this->cookieSalt . $_SERVER["REMOTE_ADDR"]), time() + 315569260, "/"); } $this->setPrivateVars($arr); } else { $loginAttempts->create(array("username" => $username, "password" => $password, "uid" => $arr["id"])); throw new Exception('Felaktiga inloggningsuppgifter.', 401); } } else { $loginAttempts->create(array("username" => $username, "password" => $password)); throw new Exception('Felaktiga inloggningsuppgifter.', 401); } }
public static function register_access_attempt($id) { $time = date('Y-m-d H:i:s'); #2015-12-14 10:01:36 $data = ['user_id' => $id, 'created_at' => $time]; $registrar = LoginAttempts::create($data); if ($registrar) { return true; } return false; }