diff --git a/api/index.php b/api/index.php
index ff8c70f58cc83632ad6bce070df5b3d18e27fba7..90ca5405c582cf6dbb0f0abb798433585cad610b 100644
--- a/api/index.php
+++ b/api/index.php
@@ -44,11 +44,10 @@
 		return;
 	}
 
-/*	TODO: add pref key to disable/enable API
-	if ($_SESSION["uid"] && !get_pref($link, 'API_ENABLED')) {
+	if ($_SESSION["uid"] && $op != "logout" && !get_pref($link, 'ENABLE_API_ACCESS')) {
 		print json_encode(array("error" => 'API_DISABLED'));
 		return;
-	} */
+	} 
 
 	switch ($op) {
 		case "getVersion":
@@ -62,7 +61,7 @@
 			if (authenticate_user($link, $login, $password)) {
 				print json_encode(array("uid" => $_SESSION["uid"]));
 			} else {
-				print json_encode(array("uid" => 0));
+				print json_encode(array("error" => "LOGIN_ERROR"));
 			}
 
 			break;
diff --git a/localized_schema.php b/localized_schema.php
index 35fb6dc0cf6fccbe15879f7d2c395747da35afaf..8d827d1dcb2398413f1a40aa0a2da05b89ceaac0 100644
--- a/localized_schema.php
+++ b/localized_schema.php
@@ -81,5 +81,6 @@
 	__("Enable inline MP3 player");
 	__("Enable the Flash-based XSPF Player to play MP3-format podcast enclosures.");
 	__("Do not show images in articles");
+	__("Enable external API");
 
 ?>
diff --git a/sanity_check.php b/sanity_check.php
index 600f8d9f40fdf2ade4bac298c45341f8a7785c5b..55df981415d06b21e29b37c792322f60d0b30e6a 100644
--- a/sanity_check.php
+++ b/sanity_check.php
@@ -2,7 +2,7 @@
 	require_once "functions.php";
 
 	define('EXPECTED_CONFIG_VERSION', 18);
-	define('SCHEMA_VERSION', 57);
+	define('SCHEMA_VERSION', 58);
 
 	if (!file_exists("config.php")) {
 		print "<b>Fatal Error</b>: You forgot to copy 
diff --git a/schema/ttrss_schema_mysql.sql b/schema/ttrss_schema_mysql.sql
index d3c8b5f1512d6deda64c322272209c431b2782d1..04c601faea3b2720e181d495a6620cc9e4ab5f59 100644
--- a/schema/ttrss_schema_mysql.sql
+++ b/schema/ttrss_schema_mysql.sql
@@ -226,7 +226,7 @@ create table ttrss_tags (id integer primary key auto_increment,
 
 create table ttrss_version (schema_version int not null) TYPE=InnoDB;
 
-insert into ttrss_version values (57);
+insert into ttrss_version values (58);
 
 create table ttrss_enclosures (id serial not null primary key,
 	content_url text not null,
@@ -359,6 +359,8 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu
 
 insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('ENABLE_OFFLINE_READING', 1, 'false', 'Enable offline reading',1,	'Synchronize new articles for offline reading using Google Gears.');
 
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('ENABLE_API_ACCESS', 1, 'false', 'Enable external API', 3);
+
 create table ttrss_user_prefs (
    owner_uid integer not null,
    pref_name varchar(250),
diff --git a/schema/ttrss_schema_pgsql.sql b/schema/ttrss_schema_pgsql.sql
index 61ffcb10a9bf6cf2e579e880f3a4bb8638b8ca47..b2458d4bada76ac69c62f7028c4777021022c929 100644
--- a/schema/ttrss_schema_pgsql.sql
+++ b/schema/ttrss_schema_pgsql.sql
@@ -202,7 +202,7 @@ create index ttrss_tags_owner_uid_index on ttrss_tags(owner_uid);
 
 create table ttrss_version (schema_version int not null);
 
-insert into ttrss_version values (57);
+insert into ttrss_version values (58);
 
 create table ttrss_enclosures (id serial not null primary key,
 	content_url text not null,
@@ -329,6 +329,8 @@ insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) valu
 
 insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id,help_text) values('ENABLE_OFFLINE_READING', 1, 'false', 'Enable offline reading',1,	'Synchronize new articles for offline reading using Google Gears.');
 
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('ENABLE_API_ACCESS', 1, 'false', 'Enable external API', 3);
+
 create table ttrss_user_prefs (
 	owner_uid integer not null references ttrss_users(id) ON DELETE CASCADE,
 	pref_name varchar(250) not null references ttrss_prefs(pref_name) ON DELETE CASCADE,
diff --git a/schema/versions/mysql/58.sql b/schema/versions/mysql/58.sql
new file mode 100644
index 0000000000000000000000000000000000000000..61173c1d5c2326640878008d834a96a9f3ba7561
--- /dev/null
+++ b/schema/versions/mysql/58.sql
@@ -0,0 +1,7 @@
+begin;
+
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('ENABLE_API_ACCESS', 1, 'false', 'Enable external API', 3);
+
+update ttrss_version set schema_version = 58;
+
+commit;
diff --git a/schema/versions/pgsql/58.sql b/schema/versions/pgsql/58.sql
new file mode 100644
index 0000000000000000000000000000000000000000..61173c1d5c2326640878008d834a96a9f3ba7561
--- /dev/null
+++ b/schema/versions/pgsql/58.sql
@@ -0,0 +1,7 @@
+begin;
+
+insert into ttrss_prefs (pref_name,type_id,def_value,short_desc,section_id) values('ENABLE_API_ACCESS', 1, 'false', 'Enable external API', 3);
+
+update ttrss_version set schema_version = 58;
+
+commit;