public static function loggaIn($namn, $losenord, $cookie = false) { global $db; $namn = Security::secure_postdata($namn); $losenord = Security::secure_postdata($losenord); if ($namn == "" || $losenord == "") { return false; } $sql = "SELECT id\n\t\t\t\tFROM " . self::classToTable(get_class()) . " \n\t\t\t\tWHERE anamn='{$namn}'"; $id = $db->value($sql); if ($id != '') { $admin = Admin::loadById($id); $losenordKrypterat = Security::encrypt_password($id, $losenord); if ($losenordKrypterat == $admin->getLosenord()) { /** Lyckad inloggning */ $sessionId = Medlem::generateSessionId(); $admin->setSessionId($sessionId); $admin->commit(); $_SESSION["mm_admin_aid"] = $id; $_SESSION["mm_admin_sid"] = $sessionId; if ($cookie) { setcookie("mm_admin_aid", $id, time() + 60 * 60 * 24 * 30, "/"); setcookie("mm_admin_Sid", $sessionId, time() + 60 * 60 * 24 * 30, "/"); } return true; } } else { throw new AdminException("Felaktigt Login/lösenord", -5); } }