var g_db=null;function opendb(){try{if(getBG().g_db_transaction_tested&&!getBG().g_db_transaction_worked)return null;if(g_db!=null)return g_db;if(window.openDatabase)(g_db=openDatabase("lp","1.0","LastPass Local Database",2E5))||console_log("Failed to open database!");else console_log("open database is not available!")}catch(a){console_log("Caught exception while opening database: "+a.message)}return g_db}
function createDataTable(a){a&&a.transaction(function(b){b.executeSql("CREATE TABLE IF NOT EXISTS LastPassData(id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, username_hash varchar(255), type varchar(20), data TEXT, CONSTRAINT usertype UNIQUE (username_hash, type))",[],function(){},function(c,d){console_log(d)})})}
function createSavedLoginsTable(a){if(a){a.transaction(function(b){b.executeSql("CREATE TABLE IF NOT EXISTS LastPassSavedLogins(username varchar(255) PRIMARY KEY, password varchar(255), last_login datetime)",[])});a.transaction(function(b){b.executeSql("CREATE TABLE IF NOT EXISTS LastPassSavedLogins2(username varchar(255) PRIMARY KEY, password text, last_login datetime, protected tinyint(1))",[])});a.transaction(function(b){b.executeSql("SELECT * FROM LastPassSavedLogins order by last_login desc",
[],function(c,d){for(var e=0;e<d.rows.length;e++){var f=d.rows.item(e).username;c.executeSql("REPLACE INTO LastPassSavedLogins2 (username, password, last_login) VALUES(?, ?, ?)",[f,d.rows.item(e).password,d.rows.item(e).last_login],function(){},function(h,g){console_log(g)});c.executeSql("DELETE FROM LastPassSavedLogins")}},function(c,d){console_log(d)})})}}
function lpSaveData(a,b){if(!(lpdisableoffline&&(b=="key"||b=="accts"||b=="otp")))if(!(g_username==null||g_username==""))if(!(a==""&&LPISLOC&&(b=="key"||b=="accts"))){var c=opendb();createDataTable(c);c&&c.transaction(function(d){d.executeSql("REPLACE INTO LastPassData (username_hash, type, data) VALUES (?, ?, ?)",[db_prepend(g_username_hash),b,a],function(){},function(e,f){console_log(f)})})}}
function createPrefsTable(a){a&&a.transaction(function(b){b.executeSql("CREATE TABLE IF NOT EXISTS LastPassPreferences (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, username_hash varchar(255), prefname varchar(255), prefvalue varchar(255), CONSTRAINT userkey UNIQUE (username_hash, prefname))",[])})}
function deletesavedpw(){var a=opendb();createSavedLoginsTable(a);a&&a.transaction(function(b){b.executeSql("UPDATE LastPassSavedLogins2 SET password = '' WHERE username = ?",[g_username],function(){g_master_password_saved=false},function(c,d){console_log(d)})})}
function protect_data(a,b,c){if(!a.length)return a;if(b&&!g_is_win)return a;if(is_chrome_portable())return a;b="";if((a!=""||g_is_mac)&&have_nplastpass()&&typeof g_nplastpass.protect_data=="function"){b=g_nplastpass.protect_data(a,c);if(typeof b!="string")b=""}if(b=="")b=a;return b}
function unprotect_data(a,b){if(!a.length)return a;if(b&&!g_is_win)return a;if(is_chrome_portable())return a;var c="";if(a!=""&&have_nplastpass()&&typeof g_nplastpass.unprotect_data=="function"){c=g_nplastpass.unprotect_data(a);if(typeof c!="string")c=""}if(c==a)c="";return c};
