function lplogincheck(a,c,b,d){if(!skiplogin()){can_chrome_do_math()||openURL(getchromeurl("mathfail.html"));yubikey_cleardata();googleauth_cleardata();sesame_cleardata();grid_cleardata();multifactor_cleardata();loginoffline(true,"logincheck");var e="method="+encodeURIComponent(get_method())+"&version="+lpversion;if(c)e+="&sessionid="+LP.en(c);if(b)e+="&wxusername="+LP.en(b);if(d)e+="&wxhash="+LP.en(d);g_lastpoll=(new Date).getTime();c=lpGetPref("logoffWhenCloseBrowser",0)==1&&lpGetPref("logoffWhenCloseBrowserVal",
0)==0?"1":"0";e+="&sessonly="+en(c);e+="&uuid="+en(getuuid());sesame_setdata("logincheckpostdata",e);lpdbg("login","Making login check request");lpMakeRequest(base_url+"login_check.php",e,lpLoginCheckResponse,lpLoginCheckError,a)}}
function LP_do_login(a,c,b,d,e,f,h,k){if(!skiplogin()){if(!e){var g=opendb();createSavedLoginsTable(g);g&&g.transaction(function(j){if(typeof b!="undefined"&&b!=null){var i=d?c:"";savedp_protected=protect_data(i,false,a);if(b)j.executeSql("REPLACE INTO LastPassSavedLogins2 (username, password, last_login, protected) VALUES(?, ?, ?, ?)",[a,savedp_protected,(new Date).getTime(),savedp_protected!=i?1:0],function(){},function(l,m){console_log(m)});else j.executeSql("DELETE FROM LastPassSavedLogins2 WHERE username=?",
[a])}});if(typeof b!="undefined"&&b!=null){lpPutGblPref("rememberemail",b?1:0);lpPutGblPref("rememberpassword",d?1:0)}if(typeof f!="undefined")lpPutGblPref("showvault",f?1:0);lpWriteAllPrefs()}yubikey_cleardata();googleauth_cleardata();sesame_cleardata();grid_cleardata();e||multifactor_cleardata();a=fix_username(a);f=get_key_iterations(a);g_local_key=h?h:make_lp_key_iterations(a,c,f);g_local_hash=k?k:make_lp_hash_iterations(g_local_key,c,f);g_local_key_hex=AES.bin2hex(g_local_key);g_local_key_hash=
SHA256(g_local_key);g_username=a;g_username_hash=SHA256(g_username);lploggedinoffline||loginoffline(true,"pluginlogin");h="xml=2&username="+en(a)+"&method="+encodeURIComponent(get_method())+"&hash="+en(g_local_hash)+"&version="+lpversion;h+="&encrypted_username="+en(lpenc(g_username,null,true));h+="&uuid="+en(getuuid());h+="&lang="+en(lpGetPref("language","en-US"));h+="&iterations="+en(get_key_iterations(a));k=lpGetPref("logoffWhenCloseBrowser",0)==1&&lpGetPref("logoffWhenCloseBrowserVal",0)==0?"1":
"0";h+="&sessonly="+en(k);sesame_cleardata();sesame_setdata("postdata",h);sesame_setdata("from","login");yubikey_cleardata();yubikey_setdata("postdata",h);yubikey_setdata("from","login");yubikey_setdata("p",c);googleauth_cleardata();googleauth_setdata("postdata",h);googleauth_setdata("from","login");googleauth_setdata("p",c);grid_cleardata();grid_setdata("postdata",h);grid_setdata("from","login");e||multifactor_cleardata();multifactor_setdata("postdata",h);multifactor_setdata("from","login");h+="&otp=";
h+="&sesameotp=";h+="&multifactorresponse=";GetOTPHash(h)}}
function loginoffline(a,c){if(!skiplogin())if(g_local_key==null||g_username==null||g_username_hash==null){if(c!="frompipes"){var b=opendb();createSavedLoginsTable(b);b&&b.transaction(function(d){d.executeSql("SELECT * FROM LastPassSavedLogins2 order by last_login desc",[],function(e,f){var h="",k="";if(f.rows.length>0){h=f.rows.item(0).username;k=f.rows.item(0).password;if(f.rows.item(0)["protected"])k=unprotect_data(k)}if((!LPISLOC||!LPISUPEK)&&h.length>0&&k.length>0){g_username=h.toLowerCase().replace(/\s*/g,
"");g_username_hash=SHA256(h);h=get_key_iterations(g_username);g_local_key=make_lp_key_iterations(g_username,k,h);g_local_hash=make_lp_hash_iterations(g_local_key,k,h);g_local_key_hex=AES.bin2hex(g_local_key);g_local_key_hash=SHA256(g_local_key);loginoffline1(a,c)}else{LPISLOC&&b.transaction(function(g){g.executeSql("SELECT prefvalue FROM LastPassPreferences where username_hash=? and prefname=?",["","openloginstart"],function(j,i){if(LPISUPEK||i.rows.length==1&&i.rows.item(0).prefvalue)if(lpGetPref("openloginstart",
LPISUPEK?1:0)==1){g_reprompt_error_callback=g_reprompt_callback=null;open_login()}},function(j,i){console_log(i)})});lpdbg("login","Trying to log in offline1: skipping because we dont have the user's key")}},function(){lpdbg("login","Trying to log in offline2: skipping because we dont have the user's key")})})}}else loginoffline1(a,c)}
function read_key_from_file(){var a="";if(have_nplastpass()&&typeof g_nplastpass.read_file=="function"){a=g_nplastpass.read_file(db_prepend(g_username_hash+"_lpall.slps"));a=typeof a!="string"?"":unprotect_data(a,true)}return a}
function read_accts_from_file(){var a="";if(have_nplastpass()&&typeof g_nplastpass.read_file=="function"){a=g_nplastpass.read_file(db_prepend(g_username_hash+"_lps.act.sxml"));if(typeof a!="string")a="";else{a=unprotect_data(a,true);a=checkIterationsInDataFile(a);if(a=="iterationserror"){lpdbg("login","Key iterations mismatch");return""}a=lpdec(a)}}return a}
function loginoffline1(a,c,b){if(a){if(!g_loggedinoffline){console_log("DB:opening database");var d=opendb();console_log("DB:opened database db="+d);createDataTable(d);if(d){console_log("DB:created database");d.transaction(function(e){var f=function(j,i){console_log("DB:inside transaction A");if(i.rows.length!=2){console_log("DB:inside transaction B");if(LPISLOC)if(!LPISUPEK||b||g_username==""||AES.hex2bin(SHA256(g_username+""))==g_local_key)lpshowError("LoginError",false,true);else{g_pwdeckey=g_local_key;
lpWriteKeyFile();g_local_accts_version=0;if(LPISUPEK){g_prompts.login_site_prompt=true;g_prompts.edit_site_prompt=true;g_prompts.edit_sn_prompt=true;g_prompts.view_pw_prompt=true;g_prompts.view_ff_prompt=true;g_prompts.switch_identity_prompt=true;g_prompts.switch_f_prompt=true;g_prompts.multifactor_reprompt=true}rewritelocalfile();loginoffline1(a,c,true)}console_log("DB:inside transaction C");lpdbg("login","Trying to log in offline : offline before online failed : could not read keyfile or accts")}else{console_log("DB:inside transaction D");
var l=i.rows.item(0).type=="key"?0:1,m=i.rows.item(l).data;l=false;m=m.split("\n");if(m.length==2)if(lpdec(m[1],g_local_key)=="lastpass rocks"){console_log("DB:inside transaction E");l=true}if(l){console_log("DB:inside transaction G");l=i.rows.item(0).type=="accts"?0:1;m=i.rows.item(l).data;m=m.substring(0,220);m=checkIterationsInDataFile(m);if(m=="iterationserror")lpdbg("login","Key iterations mismatch, bailing on loginoffline");else if(m.indexOf("type=sesameoffline\ndata=")>=0||m.indexOf("type=yubikeyoffline\ndata=")>=
0||m.indexOf("type=trueapioffline\ndata=")>=0||m.indexOf("type=omnikeyoffline\ndata=")>=0){console_log("DB:inside transaction H");lpdbg("login","Data is encoded with multifactor key, bailing on loginoffline")}else{console_log("DB:inside transaction I");offlineloginsuccessful(c,true);lpdbg("login","Trying to log in offline : offline before online successful")}}else{console_log("DB:inside transaction F");LPISLOC&&lpshowError("LoginError",false,true);lpdbg("login","Trying to log in offline: skipping because we have an incorrect user's key")}}},
h=function(){lpdbg("login","Trying to log in offline3: skipping because we dont have the user's key")};if(LPISLOC){var k=read_key_from_file(),g=read_accts_from_file();k!=""||g!=""?f(e,{rows:{length:2,item:function(j){return j==0?{type:"key",data:k}:{type:"accts",data:g}}}}):f(e,{rows:{length:0}})}else e.executeSql("SELECT * FROM LastPassData WHERE username_hash=? AND (type=? OR type=?)",[db_prepend(g_username_hash),"key","accts"],f,h)})}else console_log("DB:failed to create database db="+d)}}else if(!g_loggedinoffline){d=
opendb();createDataTable(d);d&&d.transaction(function(e){var f=function(g,j){if(j.rows.length!=2)lpdbg("login","Trying to log in offline : offline before online failed : could not read keyfile or accts");else{var i=j.rows.item(0).type=="key"?0:1,l=j.rows.item(i).data;i=false;l=l.split("\n");if(l.length==2)if(lpdec(l[1],g_local_key)=="lastpass rocks")i=true;if(i){i=j.rows.item(0).type=="accts"?0:1;l=j.rows.item(i).data;l=l.substring(0,220);l=checkIterationsInDataFile(l);if(l=="iterationserror")lpdbg("login",
"Trying to log in offline: skipping because we have a key iterations mismatch");else if(l.indexOf("type=sesameoffline\ndata=")>=0){lpdbg("sesame","Logging in offline and existing file is protected by sesameoffline => asking user for offline password");sesame_setdata("offline",1);sesame_getotp(null)}else if(l.indexOf("type=trueapioffline\ndata=")>=0||l.indexOf("type=omnikeyoffline\ndata=")>=0){lpdbg("multifactor","Logging in offline and existing file is protected by trueapioffline => asking user for offline password");
i=l.indexOf("type=trueapioffline\ndata=")>=0?"trueapi":"omnikey";multifactor_setdata("offline",1);multifactor_setdata("type",i);multifactor_getresponse(g_username)}else if(l.indexOf("type=yubikeyoffline\ndata=")>=0){yubikey_setdata("offline",1);yubikey_getotp(null)}else{offlineloginsuccessful(c,false);lpdbg("login","Trying to log in offline : offline after online successful")}}else lpdbg("login","Trying to log in offline: skipping because we have an incorrect user's key")}};if(LPISLOC){var h=read_key_from_file(),
k=read_accts_from_file();h!=""||k!=""?f(e,{rows:{length:2,item:function(g){return g==0?{type:"key",data:h}:{type:"accts",data:k}}}}):f(e,{rows:{length:0}})}else e.executeSql("SELECT * FROM LastPassData WHERE username_hash=? AND (type=? OR type=?)",[db_prepend(g_username_hash),"key","accts"],f)})}}
function offlineloginsuccessful(a,c){LPISLOC&&a=="pluginlogin"&&lpGetPref("showvault",0)==1&&openvault(1);console_log("offlineloginsuccessful!");g_loggedinonline||(g_loggedinoffline=true);lploggedin=true;lpReadAllPrefs();loggedIn(a=="pluginlogin");readrsaprivatekeyhexfromdb();if(a!="offline"){console_log("offlineloginsuccessful : from "+a+" so calling get_accts_local!");get_accts_local(true)}if(g_notifytimerid){clearTimeout(g_notifytimerid);g_notifytimerid=null}g_notifytimerid=setTimeout(function(){notifyoffline(a)},
c?3E4:0);if(g_retryonlinetimerid){clearTimeout(g_retryonlinetimerid);g_retryonlinetimerid=null}g_retryonlinetimerid=setTimeout(function(){retryonlinelogin(3E4)},3E4)}function notifyoffline(){if(lploggedin&&g_loggedinoffline){lpdbg("login","Trying to log in offline : notify user that they are logged in offline");LPISLOC||lpshowError("LoggedInOffline",false,false,false,null,true)}}
function retryonlinelogin(a){if(lploggedin&&g_loggedinoffline){lpdbg("login","We're still logged in offline => retrying to login online.  retryinterval="+a/6E4+" minutes");lplogincheck("retryonline");var c=2*a;if(c>12E5)c=12E5;setTimeout(function(){retryonlinelogin(c)},c)}}function lpTurnOffIcon(){lploggedin=false;drawIconAtRotation(0)}
function lpLoginCheckResponse(a,c,b){try{if(a&&a.readyState==4&&typeof c=="function"&&(a.status!=200||a.responseXML==null||a.responseXML.documentElement==null))c();else{if(a.readyState==4&&a.status==200&&a.responseXML!=null&&a.responseXML.documentElement!=null){var d=a.responseXML.documentElement.getElementsByTagName("ok");if(d.length>0){var e=d[0].getAttribute("lpusername");g_username=e;g_username_hash=SHA256(g_username);if(b!="retryonline"&&b!=true){lpReadAllPrefs(function(){lpLoginCheckResponseStep2(a,
e,b)});return}}}lpLoginResponse_win(a,b,true)}}catch(f){L("loginresponse: "+f)}}
function lpLoginCheckResponseStep2(a,c,b){try{var d=a.responseXML.documentElement.getElementsByTagName("ok");lpdbg("login","lpLoginCheckResponseStep2");var e=d[0].getAttribute("sesamepassword")!=null&&d[0].getAttribute("sesamepassword")!=""?true:false,f=d[0].getAttribute("yubikeyhash")!=null&&d[0].getAttribute("yubikeyhash")!=""?true:false,h=d[0].getAttribute("googleauthenabled")!=null&&d[0].getAttribute("googleauthenabled")=="1"?true:false,k=d[0].getAttribute("gridenabled")!=null&&d[0].getAttribute("gridenabled")!=
""?true:false,g=d[0].getAttribute("multifactorenabled")!=null&&d[0].getAttribute("multifactorenabled")!=""?true:false,j=d[0].getAttribute("sesameotpok")!=null&&d[0].getAttribute("sesameotpok")!=""?true:false,i=d[0].getAttribute("yubikeyotpok")!=null&&d[0].getAttribute("yubikeyotpok")!=""?true:false,l=d[0].getAttribute("googleauthotpok")!=null&&d[0].getAttribute("googleauthotpok")!=""?true:false,m=d[0].getAttribute("gridresponseok")!=null&&d[0].getAttribute("gridresponseok")!=""?true:false,n=d[0].getAttribute("multifactorresponseok")!=
null&&d[0].getAttribute("multifactorresponseok")!=""?true:false;if(!(b=="websitelogin"||b=="webrootwebsitelogin"||b=="websiterefresh"||b=="websiterefreshrsa"||b=="2ndfactorok"||b=="frompipes")&&(g_local_key==null||g_local_key=="")&&lpGetPref("logoffWhenCloseBrowser",0)==1){var o=lpGetPref("lastpollcheck",0),r=lpGetPref("logoffWhenCloseBrowserVal",0),p=lp_get_gmt_timestamp()*1E3-o;console_log(o+" "+r+" "+p);if(p>=r*6E4){loggedOut(false,"logoffWhenCloseBrowser lastpollcheck="+o+" logoffWhenCloseBrowserVal="+
r+" timesincelastpollcheck="+p);if(lpGetPref("openloginstart",LPISUPEK?1:0)==1){g_reprompt_error_callback=g_reprompt_callback=null;open_login()}return}}if(b=="httptest"){if(e)if(j){b="2ndfactorok";lpdbg("login","LoginCheck : sesame reprompt-rerequest succeeded!")}else{lpdbg("login","LoginCheck : Asking for sesame OTP and reissuing request to login_check.php");lpdbg("sesame","LOGIN CHECK RESPONSE: sesameenabled => Asking user for OTP and then reissuing the login_check request");sesame_setdata("fromwebsite",
b);sesame_getotp(c);return}if(f)if(i){b="2ndfactorok";lpdbg("login","LoginCheck : yubikey reprompt-rerequest succeeded!")}else{lpdbg("login","LoginCheck : Asking for yubikey OTP and reissuing request to login_check.php");lpdbg("yubikey","LOGIN CHECK RESPONSE: yubikeyenabled => Asking user for OTP and then reissuing the login_check request");yubikey_setdata("fromwebsite",b);yubikey_getotp(c);return}if(h)if(l){b="2ndfactorok";lpdbg("login","LoginCheck : googleauth reprompt-rerequest succeeded!")}else{lpdbg("login",
"LoginCheck : Asking for googleauth OTP and reissuing request to login_check.php");lpdbg("googleauth","LOGIN CHECK RESPONSE: googleauthenabled => Asking user for OTP and then reissuing the login_check request");googleauth_setdata("fromwebsite",b);googleauth_getotp(c);return}if(k)if(m){b="2ndfactorok";lpdbg("login","LoginCheck : grid reprompt-rerequest succeeded!")}else{lpdbg("login","LoginCheck : Asking for grid response and reissuing request to login_check.php");lpdbg("grid","LOGIN CHECK RESPONSE: gridenabled => Asking user for coordinates and then reissuing the login_check request");
grid_setdata("fromwebsite",b);grid_setdata("wxsessid",d[0].getAttribute("wxsessid"));grid_getvalues(c,d[0].getAttribute("challenge"));return}if(g)if(n){b="2ndfactorok";lpdbg("login","LoginCheck : multifactor reprompt-rerequest succeeded!");multifactor_getdata("type")=="omnikey"&&multifactor_setdata("password_offline",d[0].getAttribute("multifactorofflinepassword"))}else{lpdbg("login","LoginCheck : Asking for multifactor response and reissuing request to login_check.php");lpdbg("multifactor","LOGIN CHECK RESPONSE: multifactorenabled => Asking user for coordinates and then reissuing the login_check request");
multifactor_setdata("fromwebsite",b);multifactor_setdata("wxsessid",d[0].getAttribute("wxsessid"));multifactor_setdata("type",d[0].getAttribute("type"));multifactor_getresponse(c,d[0].getAttribute("challenge"));return}}lpLoginResponse_win(a,b,true)}catch(s){console_log(s)}}
function lpLoginResponse(a,c,b){try{console_log("Got login response");if(a&&a.readyState==4&&typeof c=="function"&&(a.status!=200||a.responseXML==null||a.responseXML.documentElement==null))c();else{console_log("Processing login response");lpLoginResponse_win(a,b,false);lpGetPref("showvault",0)==1&&openvault(1)}}catch(d){L("loginresponse: "+d)}}
function lp_login_from_saved(){try{var a=opendb();createSavedLoginsTable(a);a&&a.transaction(function(b){b.executeSql("SELECT * FROM LastPassSavedLogins2 order by last_login desc",[],function(d,e){if(e.rows.length>0){var f=e.rows.item(0).password;if(e.rows.item(0)["protected"])f=unprotect_data(f);if((!LPISLOC||!LPISUPEK)&&f!=""){console_log("Logging in from saved");var h=e.rows.item(0).username;LP_do_login(h,f,true,true);return}}a.transaction(function(k){k.executeSql("SELECT prefvalue FROM LastPassPreferences where username_hash=? and prefname=?",
["","openloginstart"],function(g,j){if(LPISUPEK||j.rows.length==1&&j.rows.item(0).prefvalue)if(lpGetPref("openloginstart",LPISUPEK?1:0)==1){g_reprompt_error_callback=g_reprompt_callback=null;open_login()}},function(g,j){console_log(j)})})},function(d,e){console_log(e)})})}catch(c){console_log(c)}}
function lpLoginCommon(){g_loggedinonline=true;g_loggedinoffline=false;if(g_notifytimerid){clearTimeout(g_notifytimerid);g_notifytimerid=null}if(g_retryonlinetimerid){clearTimeout(g_retryonlinetimerid);g_retryonlinetimerid=null}}var lploginerrorhandlercalled=0;
function lpLoginError(){console_log("Got Login Error");var a=(new Date).getTime();if(!(a-lploginerrorhandlercalled<1E3)){lploginerrorhandlercalled=a;lpdbg("login","Login via login.php failed => try logging in offline using saved credentials -- if not already logged in offline --");loginoffline(false,"ErrorHandler")}}function lpLoginCheckError(){lpdbg("login","Got lpLoginCheckError");if(!g_loggedinoffline){lpshowError("ErrorLoginMsg");loggedOut(false,"lpLoginCheckError");lp_login_from_saved()}}
function lpLoginResponse_win(a,c,b){if(a)if(a.readyState==4&&a.status==200&&a.responseXML!=null&&a.responseXML.documentElement!=null){var d=a.responseXML.documentElement,e=d.getElementsByTagName("ok"),f=false;lpdbg("login","lpLoginResponse_win");if(e.length>0){lpdbg("login","got login ok");g_username=e[0].getAttribute("lpusername");if(e[0].getAttribute("pwresetreqd")=="1"){a=g_username;b?openurlifnotopen(base_url+"passwordreset.php?u="+en(a)):window.open(base_url+"passwordreset.php?u="+en(a))}else{if(e[0].getAttribute("iterations")){f=
parseInt(e[0].getAttribute("iterations"));localStorage.setItem(SHA256(g_username)+"_key_iter",f)}g_pwdeckey=AES.hex2bin(SHA256(e[0].getAttribute("pwdeckey")));g_username_hash=SHA256(g_username);g_uid=lpuid=e[0].getAttribute("uid");g_logoff_other_ses=e[0].getAttribute("logoff_other_ses")=="1"?true:false;g_generatedpw=e[0].getAttribute("generatedpw")=="1"?true:false;countryfromip=e[0].getAttribute("country");g_lastpollcheck=g_lastpoll=(new Date).getTime();g_token=lptoken=e[0].getAttribute("token");
f=getsinglefactortype();if(e[0].getAttribute("multifactor_singlefactor")=="1"){if(f=="")if(multifactor_getdata("type")=="trueapi")have_nplastpass()&&typeof g_nplastpass.trueapi_default_login_exists=="function"&&g_nplastpass.trueapi_default_login_exists(g_username)&&setsinglefactortype(multifactor_getdata("type"));else if(e[0].getAttribute("singlefactortype")=="vtapi")have_nplastpass()&&typeof g_nplastpass.lpvt_has_data=="function"&&g_nplastpass.lpvt_has_data()&&setsinglefactortype(e[0].getAttribute("singlefactortype"));
else if(e[0].getAttribute("singlefactortype")=="validity")have_nplastpass()&&typeof g_nplastpass.validity_has_data=="function"&&g_nplastpass.validity_has_data()&&setsinglefactortype(e[0].getAttribute("singlefactortype"));else e[0].getAttribute("singlefactortype")=="winbio"&&have_nplastpass()&&typeof g_nplastpass.winbio_has_data=="function"&&g_nplastpass.winbio_has_data()&&setsinglefactortype(e[0].getAttribute("singlefactortype"))}else f!=""&&disable_single_factor();sesame_setdata("password_offline",
e[0].getAttribute("sesamepassword"));yubikey_setdata("password_offline",e[0].getAttribute("yubikeyhash"));lpLoginResponse_win1_5(a,c,b);lpLoginCommon(b);if(lpdisableoffline=e[0].getAttribute("disableoffline")==1?1:0){lpdbg("disableoffline","enabled => clearing sensitive files");clearCache(true,false,false)}}}else{b=d.getElementsByTagName("error");if(b.length>0){lpdbg("login","got login error");if(b[0].getAttribute("iterations")){f=parseInt(b[0].getAttribute("iterations"));localStorage.setItem(SHA256(g_username)+
"_key_iter",f);a=yubikey_getdata("p");LP_do_login(g_username,a);return}if(b[0].getAttribute("openurl")){f=b[0].getAttribute("openurl");window.open(f)}if(b[0].hasAttribute("invalidsession")){window.open(base_url+"invalidsession.php");lpshowError(b.length>0&&b[0].getAttribute("message")?b[0].getAttribute("message"):"LoginError",false,true);clearCache(true,false,false);loggedOut(false,"invalidsession");return}else f=parseInt(b[0].getAttribute("silent"))==1;if(a.responseText.indexOf("sesameotprequired")>
0){lpdbg("sesame","LOGIN RESPONSE: sesameenabled => Asking user for OTP and then reissuing the login request");clearCache(true,false,false);sesame_setdata("fromwebsite",c);sesame_getotp(g_username);return}if(a.responseText.indexOf("sesameotpfailed")>0){lpshowError(b.length>0&&b[0].getAttribute("message")?b[0].getAttribute("message"):"LoginError",false,true);clearCache(true,false,false);loggedOut(false,"sesameotpfailed");return}if(a.responseText.indexOf("otprequired")>0){lpdbg("yubikey","LOGIN RESPONSE: yubikeyenabled => Asking user for OTP and then reissuing the login request");
clearCache(true,false,false);yubikey_setdata("fromwebsite",c);yubikey_getotp(g_username);return}if(a.responseText.indexOf("otpfailed")>0){lpshowError(b.length>0&&b[0].getAttribute("message")?b[0].getAttribute("message"):"LoginError",false,true);clearCache(true,false,false);loggedOut(false,"otpfailed");return}e=false;if(a.responseText.indexOf("googleauthfailed")>0){e=googleauth_getdata("fail_count");if(e==null)e=0;e++;googleauth_setdata("fail_count",e);if(e<5)e=true;else{googleauth_setdata("fail_count",
0);lpshowError(b.length>0&&b[0].getAttribute("message")?b[0].getAttribute("message"):"LoginError",false,true);clearCache(true,false,false);loggedOut(false,"otpfailed");return}}if(a.responseText.indexOf("googleauthrequired")>0||e){lpdbg("googleauth","LOGIN RESPONSE: googleauthenabled => Asking user for OTP and then reissuing the login request");clearCache(true,false,false);googleauth_setdata("fromwebsite",c);googleauth_getotp(g_username);return}if(a.responseText.indexOf("gridresponserequired")>0){lpdbg("grid",
"LOGIN RESPONSE: gridenabled => Asking user for grid response and then reissuing the login request");clearCache(true,false,false);grid_setdata("fromwebsite",c);grid_setdata("wxsessid",b[0].getAttribute("wxsessid"));grid_getvalues(g_username,b[0].getAttribute("challenge"));return}if(a.responseText.indexOf("gridresponsefailed")>0){lpshowError(b.length>0&&b[0].getAttribute("message")?b[0].getAttribute("message"):"LoginError",false,true);clearCache(true,false,false);loggedOut(false,"gridresponsefailed");
return}if(a.responseText.indexOf("multifactorresponserequired")>0){lpdbg("multifactor","LOGIN RESPONSE: multifactorenabled => Asking user for multifactor response and then reissuing the login request");clearCache(true,false,false);multifactor_setdata("fromwebsite",c);multifactor_setdata("wxsessid",b[0].getAttribute("wxsessid"));multifactor_setdata("type",b[0].getAttribute("type"));multifactor_getresponse(g_username,b[0].getAttribute("challenge"));return}if(a.responseText.indexOf("multifactorresponsefailed")>
0){lpshowError(b.length>0&&b[0].getAttribute("message")?b[0].getAttribute("message"):"LoginError",false,true,false,get_multifactor_disable_url(g_username,multifactor_getdata("type")));clearCache(true,false,false);loggedOut(false,"multifactorresponsefailed");return}}loggedOut(f,"lpLoginResponse_win A");if(f)lp_login_from_saved();else if(a.responseText.indexOf("blacklist")>0){clearCache(true,false,false);lpshowError(b.length>0&&b[0].getAttribute("message")?b[0].getAttribute("message"):"Blacklist",false,
true)}else{a=b.length>0&&b[0].getAttribute("cause")&&b[0].getAttribute("cause")=="unknownemail";lpshowError(b.length>0&&b[0].getAttribute("message")?b[0].getAttribute("message"):"LoginError",false,true,a)}}}else{loggedOut(false,"lpLoginResponse_win B");lpshowError("ErrorLoginMsg")}}function disable_single_factor(){getsinglefactortype()=="trueapi"&&have_nplastpass()&&typeof g_nplastpass.trueapi_delete_default_login=="function"&&g_nplastpass.trueapi_delete_default_login();setsinglefactortype("")}
function lpLoginResponse_win1_5(a,c,b){a.responseXML.documentElement.getElementsByTagName("ok");if(g_local_key==null||g_local_key=="")!(c=="websitelogin"||c=="webrootwebsitelogin"||c=="websiterefresh"||c=="websiterefreshrsa"||c=="2ndfactorok"||c=="frompipes")&&lpGetPref("logoffWhenCloseBrowser",0)==1?lpReadAllPrefs(function(){lpLoginResponse_win1_75(a,c,b)}):lpReadKeyFile(a,c,false,b);else{lpWriteKeyFile();lpReadAllPrefs(function(){lpLoginResponse_win2(a,c,b)})}}
function lpLoginResponse_win1_75(a,c,b){var d=lpGetPref("lastpollcheck",0),e=lpGetPref("logoffWhenCloseBrowserVal",0),f=lp_get_gmt_timestamp()*1E3-d;f>=e*6E4?loggedOut(false,"lpLoginResponse_win1_75 lastpollcheck="+d+" logoffWhenCloseBrowserVal="+e+" timesincelastpollcheck="+f):lpReadKeyFile(a,c,false,b)}
function lpLoginResponse_win2(a,c,b){var d=a.responseXML.documentElement;d=d.getElementsByTagName("ok");closeallnotifications(true);lp_phpsessid=d[0].getAttribute("sessionid");loggedIn();g_server_accts_version=parseInt(d[0].getAttribute("accts_version"));if(g_server_accts_version!=g_local_accts_version)g_local_accts_version=-1;g_loglogins=parseInt(d[0].getAttribute("loglogins"));g_isadmin=parseInt(d[0].getAttribute("isadmin"))==1;g_iscompanyadmin=parseInt(d[0].getAttribute("companyadmin"))==1;iconsversion=
parseInt(d[0].getAttribute("iconsversion"));lpCheckDownloadNewDataFile(d[0].getAttribute("formfillver"),"ff.dat",ffver,"ff","ff.dat");lpCheckDownloadNewDataFile(d[0].getAttribute("sitesver"),"sites.dat",-1,"sites","sites.dat");if(d[0].getAttribute("privatekeyenchash")=="")if(have_nplastpass()&&typeof g_nplastpass.xGenerateKeys=="function"){d=AES.bin2hex(g_local_key).toUpperCase();d=g_nplastpass.xGenerateKeys(d).split("|");d.length==2&&upload_rsa_keys({privatekey:atob(d[0]),publickey:atob(d[1])})}else{if(g_ischrome){d=
new RSAKey;generate_key(d,upload_rsa_keys)}}else readrsaprivatekeyhexfromdb(false,true,d[0].getAttribute("privatekeyenchash"));if(!b||typeof c=="boolean"&&c)lpnp_notify("internal_logincheck_ack",{data0:lp_phpsessid,data1:g_username,data2:g_identity});d=a.responseXML.documentElement;d=d.getElementsByTagName("ok");if(lpGetPref("storeLostOTP",1)==1&&d[0].hasAttribute("lostpwotpresult")&&d[0].getAttribute("lostpwotpresult")!="ok"){DeleteOTP();MakeOTP()}if(!hassites()||g_server_accts_version!=g_local_accts_version){console_log("!hassites() or server_ver:"+
g_server_accts_version+" != local_ver:"+g_local_accts_version+" so calling get_accts_local!");get_accts_local()}checkIconsVersion(iconsversion);lpretryrequests()}
function lpCheckDownloadNewDataFile(a,c,b,d,e){if(!(a==""||a==0)){var f=b;c=localStorage.getItem(e);b=false;if(c!=null&&c!=""){f=c.indexOf("\n")==-1?c.length:c.indexOf("\n");f=c.substr(0,f)}else b=true;if(f!=null&&f!=""&&f!=-1&&CompareLastPassVersions(a,f)>0)b=true;b&&lpMakeRequest(base_url+"getappdata.php","type="+en(d),lpDownloadDataResponse,null,e)}}var adminoverride="",lplastgetaccounts=0;
function get_accts(){var a=(new Date).getTime();if(!(a-lplastgetaccounts<1E3)){lplastgetaccounts=a;a=base_url+"getaccts.php?mobile=1&b64=1&shap=1&u="+g_username_hash;if(adminoverride!="")a+="&adminoverride="+en(adminoverride);lpMakeRequest(a,"",lpAcctsResponse,lpAcctsError)}}function get_accts_local(a){lpReadAcctsData(a)}
function lpAcctsResponse(a){if(a&&a.readyState==4){a=atob(a.responseText);lp_enterpriseuser=lp_premium_exp=0;var c=get_ff_translation("ff_captcha_regexp");lp_captcha_regexp=c!=""?RegExp(c,"i"):null;parsemobile(a,a.length,100,0,postacctsload,[],[],[],[],[],[],[],true,false,null,[],[],[],[],[],[],lp_rsaprivatekeyhex,[],null,null,null,[]);g_premium_exp=lp_premium_exp;g_enterpriseuser=lp_enterpriseuser}}
function get_ff_translation(a){var c=lpGetPref("language","");if(c=="")c=navigator.language;c=c.replace("-","_");if(c=="es_MX")c="es_419";if(typeof translations[c]=="undefined")c=c.substring(0,2);if(typeof translations[c]=="undefined")for(var b in translations)if(b.substring(0,2)==c){c=b;break}if(typeof translations[c]=="undefined")c="en_US";return typeof translations[c]!="undefined"&&typeof translations[c][a]!="undefined"&&translations[c][a]!=""?translations[c][a]:typeof translations.en_US!="undefined"&&
typeof translations.en_US[a]!="undefined"&&translations.en_US[a]!=""?translations.en_US[a]:""}
function rewritelocalfile(a,c,b){b=typeof b=="undefined"?null:b;var d=flattendata(g_local_accts_version,g_sites,g_securenotes,g_prompts,g_formfills,g_identities,g_equivalentdomains,g_neverurls,g_premium_exp,lpenc(g_username),g_pendings,g_shareeautopushes,lpmaxid,g_urlrules,g_prefoverrides,g_shares,g_applications,g_enterpriseuser);d=btoa(d);if(LPISLOC||b)d="LPB64"+d;d=prependOTPAndEncrypt(d);d=prependIterations(d);lpSaveData(d,"accts");if(LPISLOC||b){d=lpenc(d);d=prependIterations(d);b||(d=protect_data(d,
true));if(have_nplastpass()&&typeof g_nplastpass.write_file=="function"){var e="";if(a)e="_"+(new Date).toString().replace(" ","_");e=db_prepend(g_username_hash+e+"_lps.act.sxml");if(b)e="lpexport.xml";g_nplastpass.write_file(e,d)}!a&&!c&&lpnp_notify("refresh_local",{data0:g_username_hash})}update_menus()}
function prependOTPAndEncrypt(a){var c=null,b="";if(sesame_getdata("password_offline")&&sesame_getdata("password_offline")!=""){lpdbg("sesame","encrypting accounts file before writing");c=sesame_getdata("password_offline");b="type=sesameoffline\ndata="}else if(multifactor_getdata("password_offline")&&multifactor_getdata("password_offline")!=""){lpdbg("multifactor","encrypting accounts file before writing");c=multifactor_getdata("password_offline");b="type="+multifactor_getdata("type")+"offline\ndata="}else if(yubikey_getdata("password_offline")&&
yubikey_getdata("password_offline")!=""){lpdbg("yubikey","encrypting accounts file before writing");c=yubikey_getdata("password_offline");b="type=yubikeyoffline\ndata="}if(c){a=enc(a,hex2bin(c));if(!a||a==""){lpdbg("error","Failed to encrypt data in save_accounts_fileraw");return false}a=b+a}return a}function clearSavedPassword(a){var c=opendb();createSavedLoginsTable(c);c&&c.transaction(function(b){b.executeSql("UPDATE LastPassSavedLogins2 SET password = '' WHERE username = ?",[a])})}
function postacctsload(a,c,b,d,e,f,h,k,g,j,i,l,m,n,o,r,p,s,q){if(lploggedin)if(!k&&(!j||j&&a.length==0)){console_log("ERROR: Could not parse accts data!!!");if(gPulledInvalidAccts)lpshowError("ErrorGetAcctsMsg");else{gPulledInvalidAccts=true;get_accts()}}else{try{if(lp_trueapi_trial_exp!=null){var v=parseInt(lp_trueapi_trial_exp);if(v>0&&v<parseInt((new Date).getTime()/1E3)){getsinglefactortype()=="trueapi"&&setsinglefactortype("");multifactor_getdata("type")=="trueapi"&&multifactor_setdata("type",
"")}}}catch(w){}if(a.length>0&&typeof i!="undefined"&&i!=null&&adminoverride==""){k=lpdec(i);if(i!=""&&i!=null&&i!="null"&&g_username!=k){lpReportError("Encrypted username check failed: "+g_username+" vs "+k+" for "+i+" local "+j,null);lpshowError("A consistency check failed while loading your sites. Please relogin.");clearSavedPassword(g_username);clearAllData();loggedOut(false,"encryptedusername_check_failed");return false}}lpmaxid=n.maxid;if(!j){g_local_accts_version=get_version(g);g=btoa(g);g=
prependOTPAndEncrypt(g);g=prependIterations(g);lpSaveData(g,"accts")}j=[];g_tlds=[];i=AES.bin2hex(g_local_key);for(g=0;g<a.length;g++){a[g].url=AES.hex2url(a[g].url);a[g].tld=lp_gettld_url(a[g].url);if(LPISLOC&&a[g].tld)try{rfdefaults||(rfdefaults=JSON.parse(lp_hex2bin(lpReadFile("rfdefaults"))));if(rfdefaults&&typeof rfdefaults[a[g].tld]!="undefined"){a[g].submit_id=rfdefaults[a[g].tld].submit_id;a[g].captcha_id=rfdefaults[a[g].tld].captcha_id;a[g].custom_js=rfdefaults[a[g].tld].custom_js}}catch(x){}n=
typeof a[g].sharefolderid=="undefined"?g_local_key:getsharekey(s,a[g].sharefolderid);if(n!=null){k=typeof a[g].sharefolderid=="undefined"?i:AES.bin2hex(n);a[g].unencryptedUsername=lpmdec(a[g].username,true,n,k)}if(typeof g_tlds[a[g].tld]=="undefined")g_tlds[a[g].tld]=[];g_tlds[a[g].tld][a[g].aid]=true;j[a[g].aid]=a[g]}i=[];for(g=0;g<c.length;g++){c[g].url=AES.hex2url(c[g].url);i[c[g].aid]=c[g]}n=[];for(g=0;g<q.length;g++){q[g].appname=AES.hex2url(q[g].appname);n[q[g].appaid]=q[g]}g_sites=j;g_securenotes=
i;g_applications=n;g_prompts=b;g_formfills=d;g_identities=e;g_equivalentdomains=f;g_urlrules=o;g_neverurls=h;g_pendings=l;g_prefoverrides=p;g_shares=s;overrideprefs(g_prefoverrides);setcachedffdat();g_shareeautopushes=[];parseAutoPushMobile(m,g_shareeautopushes);for(g=0;g<g_formfills.length;g++)g_formfills[g].decprofilename=lpmdec(g_formfills[g].profilename,true);g_formfills.sort(function(t,u){return t.decprofilename.toLowerCase()<u.decprofilename.toLowerCase()?-1:1});b=false;for(g=0;g<g_identities.length;g++){g_identities[g].deciname=
lpdec(g_identities[g].iname);if(g_identities[g].iid==g_identity)b=true}g_identities.sort(function(t,u){return t.deciname.toLowerCase()<u.deciname.toLowerCase()?-1:1});if(!b&&g_identity!=""){identityFilter="";switch_identity("",true);clearCache(true,false,false);setTimeout('loggedOut(false,"wrongidentity");',500);alert(gs("Your selected Identity no longer exists. Defaulting to 'All' and logging off."));return false}rsa_acceptpendingshares();rsa_acceptshareeautopushes();b="";if((g_is_win||g_is_mac&&
LPISLOC)&&have_nplastpass()&&typeof g_nplastpass.read_file=="function")b=g_nplastpass.read_file(db_prepend(g_username_hash+"_lt.cac"));else if(typeof localStorage!="undefined")b=localStorage.getItem(db_prepend(g_username_hash+"_lt.cac"));b=(b==null?"":b).split("\n");for(g=0;g<b.length;g++){e=b[g].split(" ");if(e.length==2&&e[0]!=""&&e[1]!=""){d=e[0];e=e[1];if(g_sites[d])if(e>g_sites[d].last_touch)g_sites[d].last_touch=e}}console_log("num sites: "+a.length+" num sn: "+c.length+" num ff: "+g_formfills.length+
" num identities: "+g_identities.length+" pendings: "+g_pendings.length+" num applications: "+g_applications.length);recheckall();update_menus()}}function setcachedffdat(){var a=localStorage.getItem("ff.dat");a=a==null?translations:LPJSON.parse(a);for(var c=[],b=0;b<g_formfills.length;b++)c[lpmdec(g_formfills[b].profilelanguage,true)]=1;var d=[];for(b in a)if(b=="en-US"||typeof c[b]!="undefined")d[b]=a[b];g_cachedffdat=LPJSON.stringify(d)}
function overrideprefs(a){if(typeof a.allowmasterpasswordsave&&a.allowmasterpasswordsave=="0"){lpPutGblPref("rememberpassword",0);g_master_password_saved=false;var c=opendb();createSavedLoginsTable(c);c&&c.transaction(function(b){b.executeSql("UPDATE LastPassSavedLogins2 SET password = '' WHERE username = ?",[g_username])})}if(typeof a.logoffclosebrowser!="undefined"&&a.logoffclosebrowser!="-1"){lpPutGblPref("logoffWhenCloseBrowser",1);lpPutGblPref("logoffWhenCloseBrowserVal",a.logoffclosebrowser)}typeof a.logoffidle!=
"undefined"&&a.logoffidle!="-1"&&lpPutUserPref("idleLogoffVal",a.logoffidle);typeof a.noexport!="undefined"&&a.noexport!="-1"&&lpPutUserPref("noexport",a.noexport);lpWriteAllPrefs()}function lpAcctsError(){L("Error xhr_accts")}
function checkIconsVersion(a){var c=opendb();createDataTable(c);c?c.transaction(function(b){b.executeSql("SELECT * FROM LastPassData WHERE username_hash=? AND type=?",[db_prepend(g_username_hash),"icons"],function(d,e){var f=true,h=null;lpGetPref("icons",-1);if(e.rows.length>0)if(lpGetPref("icons",-1)==a){f=false;h=e.rows.item(0).data}h==null||f?downloadIcons():processIcons(h)},function(d,e){console_log(e)})}):downloadIcons()}
function processIcons(a){if(a)for(;;){if(a.length<10)break;var c=/lp([^:]+):([^:]+):/.exec(a);if(!c||c.length!=3)break;var b=c[1],d=c[2];c=parseInt(d);if(isNaN(c))break;d="lp"+b+":"+d+":";g_icons[b]=lpsubstring(a,d.length,d.length+c);g_icons_length++;a=a.substring(d.length+c)}}function lpsubstring(a,c,b){var d="",e=b-c;for(b=0;b<e;++b)d+=a[b+c];return d}function downloadIcons(){lpMakeRequest(base_url+"geticon.php","versionchrome=1&username="+en(g_username),lpIconResponse,null)}
function lpIconResponse(a){if(a.readyState==4&&a.status==200&&a.responseText)if(!(a.responsetext=="latest"||a.responsetext=="nodata")){var c=a.responseText.split("\n");a=c[0].split("=")[1];c=c[1];lpPutUserPref("icons",a);lpWriteAllPrefs();lpSaveData(c,"icons");processIcons(c)}}
function loglogin(a){get_selected_tab(null,function(c){if(typeof c.incognito=="undefined"||!c.incognito){c=lp_get_gmt_timestamp();if(typeof g_sites[a]!="undefined"){if(parseFloat(c)<5+parseFloat(g_sites[a].last_touch))return;g_sites[a].last_touch=c;writenewts(a,c)}else if(typeof g_securenotes[a]!="undefined"){if(c==g_securenotes[a].last_touch)return;g_securenotes[a].last_touch=lp_get_gmt_timestamp();rewritelocalfile()}if(g_loglogins){c="id="+en(a)+"&method="+encodeURIComponent(get_method());var b=
getacct(a);if(g_loglogins>1&&b){if((g_loglogins&2)==2)c+="&u="+en(AES.url2hex(b.url));if((g_loglogins&4)==4)c+="&n="+en(AES.url2hex(b.name));if((g_loglogins&8)==8)c+="&un="+en(AES.url2hex(getusernamefromacct(b)))}if(b)if(b=issharedfolder(g_shares,b.group))c+="&sharedfolderid="+en(b.id);lpMakeRequest(base_url+"loglogin.php",c,null,null)}}})}
function writenewts(a,c){var b="";if((g_is_win||g_is_mac&&LPISLOC)&&have_nplastpass()&&typeof g_nplastpass.read_file=="function")b=g_nplastpass.read_file(db_prepend(g_username_hash+"_lt.cac"));else if(typeof localStorage!="undefined")b=localStorage.getItem(db_prepend(g_username_hash+"_lt.cac"));b=(b==null?"":b).split("\n");for(var d="",e=0;e<b.length;e++)if(b[e].indexOf(a+" ")!=0&&b[e]!="")d+=b[e]+"\n";d+=a+" "+c+"\n";if((g_is_win||g_is_mac&&LPISLOC)&&have_nplastpass()&&typeof g_nplastpass.write_file==
"function")g_nplastpass.write_file(db_prepend(g_username_hash+"_lt.cac"),d);typeof localStorage!="undefined"&&localStorage.setItem(db_prepend(g_username_hash+"_lt.cac"),d)}function logformfill(a){get_selected_tab(null,function(c){if(typeof c.incognito=="undefined"||!c.incognito)g_loglogins&&lpMakeRequest(base_url+"logformfill.php?ffid="+en(a),"",null,null)})}
function lpWriteKeyFile(){var a=AES.bin2hex(g_local_key);if(typeof g_pwdeckey!="undefined"&&g_pwdeckey!=null){a=AES.Encrypt({pass:g_pwdeckey,data:a,b64:true,mode:"ecb",bits:256});var c=AES.Encrypt({pass:g_local_key,data:"lastpass rocks",b64:true,mode:"ecb",bits:256});a=a+"\n"+c;lpSaveData(a,"key");if((g_is_win||g_is_mac||g_is_linux)&&have_nplastpass()&&typeof g_nplastpass.write_file=="function"){a=protect_data(a,true);lpdisableoffline||g_nplastpass.write_file(db_prepend(g_username_hash+"_lpall.slps"),
a)}}}
function lpReadKeyFile(a,c,b,d){b=opendb();createDataTable(b);b&&b.transaction(function(e){var f=function(g,j){if(j.rows.length>0){var i=j.rows.item(0).data;if(i){i=i.split("\n");if(i.length==2){var l=null;l=a?AES.hex2bin(lpdec(i[0],g_pwdeckey)):g_local_key;if(lpdec(i[1],l)=="lastpass rocks"){g_local_key=l;g_local_key_hex=AES.bin2hex(l);g_local_key_hash=SHA256(g_local_key);if(a){lpLoginResponse_win2(a,c,d);return}else{loggedIn();console_log("lpReadKeyFile worked, not calling get_accts_local!");get_accts_local(true)}}}}}else lp_login_from_saved();
a&&loggedOut(false,"keyfailed")},h=function(g,j){console_log(j)};if(LPISLOC){var k=read_key_from_file();k!=""?f(e,{rows:{length:1,item:function(){return{data:k}}}}):f(e,{rows:{length:0}})}else e.executeSql("SELECT * FROM LastPassData WHERE username_hash=? AND type=?",[db_prepend(g_username_hash),"key"],f,h)})}
function lpReadAcctsData(a){if(!(g_username==null||g_username=="")){var c=opendb();createDataTable(c);c?c.transaction(function(b){var d=function(h,k){if(k.rows.length>0){if((data=k.rows.item(0).data)&&data!=""){data=checkIterationsInDataFile(data);if(data=="iterationserror"){console_log("local accts data corrupt - key mismatch. redownloading");get_accts();return}if(a&&(!sesame_getdata("password_offline")||sesame_getdata("password_offline")==""||!yubikey_getdata("password_offline")||yubikey_getdata("password_offline")==
""||!multifactor_getdata("password_offline")||multifactor_getdata("password_offline")=="")){if(data.substring(0,30).indexOf("type=sesameoffline\ndata=")==0){sesame_setdata("offline","1");sesame_getotp(g_username);return}if(data.substring(0,30).indexOf("type=trueapioffline\ndata=")==0||data.substring(0,30).indexOf("type=omnikeyoffline\ndata=")==0){multifactor_setdata("offline","1");multifactor_setdata("type",data.substring(0,30).indexOf("type=trueapioffline\ndata=")==0?"trueapi":"omnikey");multifactor_getresponse(g_username);
return}if(data.substring(0,30).indexOf("type=yubikeyoffline\ndata=")==0){yubikey_setdata("offline","1");yubikey_getotp(g_username);return}}var g=null;if(sesame_getdata("password_offline")&&sesame_getdata("password_offline")!=""&&data.substring(0,30).indexOf("type=sesameoffline\ndata=")==0){lpdbg("sesame","decrypting accounts file after reading");data=data.substring(24);g=sesame_getdata("password_offline")}else if(multifactor_getdata("password_offline")&&multifactor_getdata("password_offline")!=""&&
(data.substring(0,30).indexOf("type=trueapioffline\ndata=")==0||data.substring(0,30).indexOf("type=omnikeyoffline\ndata=")==0)){lpdbg("multifactor","decrypting accounts file after reading");data=data.substring(25);g=multifactor_getdata("password_offline")}else if(yubikey_getdata("password_offline")&&yubikey_getdata("password_offline")!=""&&data.substring(0,30).indexOf("type=yubikeyoffline\ndata=")==0){lpdbg("yubikey","decrypting accounts file after reading");data=data.substring(25);g=yubikey_getdata("password_offline")}if(g)data=
dec(data,hex2bin(g))}if(LPISLOC&&data.length>=5&&data.substring(0,5)=="LPB64")data=data.substring(5);try{data=atob(data)}catch(j){console_log("local accts data corrupt. redownloading");get_accts();return}g_local_accts_version=get_version(data);if(g_local_accts_version!=g_server_accts_version&&g_server_accts_version!=-1){console_log("local accts version is outdated: local:"+g_local_accts_version+" server:"+g_server_accts_version+" redownloading");get_accts()}else{L("using cached accts data");if(hassites())L("Cached data already in place, ABORT, to avoid reparse.");
else{lp_enterpriseuser=lp_premium_exp=0;g=get_ff_translation("ff_captcha_regexp");lp_captcha_regexp=g!=""?RegExp(g,"i"):null;parsemobile(data,data.length,100,0,postacctsload,[],[],[],[],[],[],[],true,true,null,[],[],[],[],[],[],lp_rsaprivatekeyhex,[],null,null,null,[]);g_premium_exp=lp_premium_exp;g_enterpriseuser=lp_enterpriseuser}}}else g_username_hash&&get_accts()},e=function(h,k){console_log(k)};if(LPISLOC){var f=read_accts_from_file();f!=""?d(b,{rows:{length:1,item:function(){return{data:f}}}}):
d(b,{rows:{length:0}})}else b.executeSql("SELECT * FROM LastPassData WHERE username_hash=? and type=?",[db_prepend(g_username_hash),"accts"],d,e)}):get_accts()}}
function MakeOTP(){if(!(g_username==null||g_username.length==0))if(!(g_local_key==null||g_local_key.length==0)){var a=fix_username(g_username);rng_seed_time();for(var c=[],b=0;b<16;b++)c[b]=0;rng_get_bytes(c);var d="";for(b=0;b<16;b++)d+=String.fromCharCode(c[b]);c=enc(AES.bin2hex(d),g_local_key);var e=make_lp_key(g_username,d);b=enc(AES.bin2hex(g_local_key),e);a=SHA256(SHA256(a+d)+d);var f=AES.hex2bin(dec(b,e,1));if(g_local_key!=f)console_log("ERROR: Failed to decrypt newly encrypted key: dec_local_key:\n"+
AES.bin2hex(f)+" != \n"+AES.bin2hex(g_local_key)+"\nlen: "+f.length+" vs "+g_local_key.length+"\nrand pw:"+AES.bin2hex(d)+"\ng_username:"+g_username+"\nrand key:"+AES.bin2hex(e)+"\nrand_encrypted_key:"+b);else{a="newkey=1&xml=1&hash="+LP.en(a);a+="&encrypted_otp="+LP.en(c);a+="&rand_encrypted_key="+LP.en(b);a+="&recovery=1";LP.lpMakeRequest(base_url+"otp.php",a,lpOTPUploadResponse,function(){},d)}}}function DeleteOTP(){DeleteFromDB("otp")}
function DeleteFromDB(a){if(!(g_username==null||g_username==""))if(!(LPISLOC&&(a=="key"||a=="accts"))){var c=opendb();createDataTable(c);c&&c.transaction(function(b){b.executeSql("DELETE FROM LastPassData WHERE username_hash=? and type=?",[db_prepend(g_username_hash),a],function(){},function(d,e){console_log(e)})})}}
function GetOTPHash(a,c,b,d){var e=opendb();createDataTable(e);if(e){var f=b?SHA256(b):g_username_hash,h=b?b:g_username;e.transaction(function(k){k.executeSql("SELECT * FROM LastPassData WHERE username_hash=? and type=?",[db_prepend(f),"otp"],function(g,j){var i="";if(j.rows.length>0)i=j.rows.item(0).data;if(a){if(i!=""){i=AES.hex2bin(i);lostotphash=SHA256(SHA256(fix_username(h)+i)+i)}else lostotphash="";if(lpGetPref("storeLostOTP",1)==1)a+="&lostpwotphash="+en(lostotphash);sesame_setdata("postdata",
a);yubikey_setdata("postdata",a);googleauth_setdata("postdata",a);grid_setdata("postdata",a);multifactor_setdata("postdata",a);g_lastpoll=(new Date).getTime();console_log("Requesting login.php A");lpMakeRequest(base_url+"login.php",a,lpLoginResponse,lpLoginError)}else if(c){lostotphash=i==""?"nouser":i;sendCS(c,{cmd:"recover",otp:lostotphash},d)}},function(g,j){console_log(j)})})}else{g_lastpoll=(new Date).getTime();console_log("Requesting login.php B");lpMakeRequest(base_url+"login.php",a,lpLoginResponse,
lpLoginError)}}function lpOTPUploadResponse(a,c,b){if(!lpdisableoffline)if(a.readyState==4&&a.status==200&&a.responseXML&&a.responseXML.documentElement){a=opendb();createDataTable(a);a&&a.transaction(function(d){d.executeSql("REPLACE INTO LastPassData (username_hash, type, data) VALUES (?, ?, ?)",[db_prepend(g_username_hash),"otp",AES.bin2hex(b)],function(){console_log("inserted")},function(e,f){console_log(f)})})}}
function savePassword(a,c,b,d){var e=lp_gettld_url(c);if(c.indexOf("chrome://")==0||c.indexOf("chrome-extension://")==0)e=c="Browser";e=gs("Generated Password for")+" "+e;a="url="+en(AES.url2hex(c))+"&password="+en(lpenc(a))+"&name="+en(lpenc(e));a+=get_identity_param();if(d)a+="&nofill=1";lpMakeRequest(base_url+"save_gen_pw.php",a,lpPopulateGeneratedPassword,null,b)}
function lpPopulateGeneratedPassword(a,c,b){if(a.readyState==4&&a.status==200&&a.responseXML&&a.responseXML.documentElement){a=a.responseXML.documentElement;c=a.getElementsByTagName("error");if(c.length>0)if((c=c[0].getAttribute("notloggedin"))&&c=="1"){loggedOut(false,"lpPopulateGeneratedPassword");return}a=a.getElementsByTagName("ok");if(a.length>0){c=AES.hex2url(a[0].getAttribute("url"));var d=crypto_atob(a[0].getAttribute("password"));sendCS(b,{cmd:"populategeneratedpassword",url:c,password:lpmdec(d,
true),nofill:a[0].getAttribute("nofill")});b=createNewAcct();b.tld=lp_gettld_url(c);var e=gs("Generated Password for")+" "+b.tld;b.aid=a[0].getAttribute("aid");if(typeof g_tlds[b.tld]=="undefined")g_tlds[b.tld]=[];g_tlds[b.tld][b.aid]=true;add_ident_aid(b.aid);b.url=c;b.name=e;b.password=d;b.genpw=1;g_sites[b.aid]=b;g_local_accts_version++;rewritelocalfile();b=a[0].getAttribute("accts_version");compare_accounts_versions(b,g_local_accts_version)||get_accts();refresh_windows()}}}
function addeditformfill(a,c){var b="",d;for(d in a)b+=(b==""?"":"&")+d+"="+en(a[d]);b+=get_identity_param();lpMakeRequest(base_url+"formfill.php",b,lpAddEditFormFillResponse,null,c)}function deleteformfill(a){for(var c=0;c<g_formfills.length;c++)if(g_formfills[c].ffid==a){g_formfills.splice(c,1);break}g_local_accts_version++;rewritelocalfile();c="deleteext=1&ffid="+LP.en(a);c+=get_identity_param();lpMakeRequest(base_url+"formfill.php",c,lpDeleteFormFillResponse,null,a)}
function lpAddEditFormFillResponse(a,c,b){if(a.readyState==4&&a.status==200&&a.responseXML&&a.responseXML.documentElement){a=a.responseXML.documentElement;c=a.getElementsByTagName("error");if(c.length>0)if((c=c[0].getAttribute("notloggedin"))&&c=="1"){loggedOut(false,"lpAddEditFormFillResponse");return}c=a.getElementsByTagName("result");if(c.length>0){c[0].getAttribute("msg");a=c[0].getAttribute("ffid");var d=c[0].getAttribute("cfids");c=c[0].getAttribute("accts_version");var e=[],f=d==""?[]:d.split(","),
h=0;for(d=1;typeof b["customfield"+d+"cfid"]!="undefined";++d){var k={};k.cfid=b["customfield"+d+"cfid"]!=0?b["customfield"+d+"cfid"]:h<f.length?f[h++]:0;k.text=b["customfield"+d+"text"];k.value=b["customfield"+d+"value"];k.alttext=b["customfield"+d+"alttext"];e.push(k)}f=b.cmd;delete b.cmd;delete b.deleteext;for(d=1;;++d){if(typeof b["customfield"+d+"cfid"]=="undefined")break;delete b["customfield"+d+"cfid"];delete b["customfield"+d+"text"];delete b["customfield"+d+"value"];delete b["customfield"+
d+"alttext"]}b.custom_fields=e;if(f=="add"){b.ffid=a;add_ident_ffid(a);g_formfills.push(b)}else for(d=0;d<g_formfills.length;++d)if(a==g_formfills[d].ffid){g_formfills[d]=b;break}g_formfills.sort(function(g,j){return g.decprofilename.toLowerCase()<j.decprofilename.toLowerCase()?-1:1});g_local_accts_version++;rewritelocalfile();compare_accounts_versions(c,g_local_accts_version)||get_accts();refresh_windows()}}}
function lpDeleteFormFillResponse(a){if(a.readyState==4&&a.status==200&&a.responseXML&&a.responseXML.documentElement){a=a.responseXML.documentElement;var c=a.getElementsByTagName("error");if(c.length>0)if((c=c[0].getAttribute("notloggedin"))&&c=="1"){loggedOut(false,"lpDeleteFormFillResponse");return}a=a.getElementsByTagName("result");if(a.length>0){a=a[0].getAttribute("accts_version");compare_accounts_versions(a,g_local_accts_version)||get_accts();refresh_windows()}}}
function saveSiteFromSubmit(a,c){a+="&auto=1"+get_identity_param();try{for(var b in g_sites)if(g_sites[b].genpw&&g_sites[b].tld==c.tld&&lpmdec_acct(g_sites[b].password,true,g_sites[b],g_shares)==lpmdec_acct(c.password,true,c,g_shares)){a+="&delgenpwaid="+LP.en(b);break}}catch(d){}c.postdata=a;c.posturl=base_url+"deliver_and_add.php";lpMakeRequest(base_url+"deliver_and_add.php",a,lpSaveSiteResponse,null,c)}
function updateFieldsFromSubmit(a,c){a+="&auto=1"+get_identity_param();lpMakeRequest(base_url+"gm_deliver.php",a,lpUpdateFieldsResponse,null,c)}function saveAllSite(a,c){a+="&auto=1"+get_identity_param();c.postdata=a;c.posturl=base_url+"show.php";lpMakeRequest(base_url+"show.php",a,lpSaveSiteResponse,null,c)}function saveSite(a,c){a+="&auto=1"+get_identity_param();c.postdata=a;c.posturl=base_url+(is_application(c)?"addapp.php":"show.php");lpMakeRequest(c.posturl,a,lpSaveSiteResponse,null,c)}
function openLinkedSites(a,c){setTimeout(function(){openchangepw(a,c)},700)}
function lpSaveSiteResponse(a,c,b){if(!rsa_shareeautopushesresponse(a,{url:b.posturl,aid:b.aid,postdata:b.postdata,handler:lpSaveSiteResponse,param:b,newvalues:b.newvalues}))if(a.readyState==4&&a.status==200&&a.responseXML&&a.responseXML.documentElement){a=a.responseXML.documentElement;c=a.getElementsByTagName("error");if(c.length>0)if((c=c[0].getAttribute("notloggedin"))&&c=="1"){loggedOut(false,"lpSaveSiteResponse");return}a=a.getElementsByTagName("result");if(a.length>0){a[0].getAttribute("msg")==
"accountreplaced"&&g_local_accts_version++;b.submit_id=a[0].getAttribute("submit_id");b.captcha_id=a[0].getAttribute("captcha_id");b.custom_js=a[0].getAttribute("custom_js");if(b.aid=="0"){var d=a[0].getAttribute("aid");c=a[0].getAttribute("urid");b.aid=b.fiid=d;b.urid=c;if(b.fields){var e=get_ff_translation("ff_captcha_regexp");d=e!=""?RegExp(e,"i"):null;for(e=0;e<b.fields.length;e++){if(!b.fields[e].otherfield&&b.fields[e].otherlogin!="1")b.fields[e].urid=c;if(d&&(typeof b.captcha_id=="undefined"||
b.captcha_id=="")&&b.fields[e].type=="text"&&d.exec(b.fields[e].name))b.captcha_id=b.fields[e].name}}add_ident_aid(b.aid);if(b.sn)g_securenotes[b.aid]=b;else{if(typeof g_tlds[b.tld]=="undefined")g_tlds[b.tld]=[];g_tlds[b.tld][b.aid]=true;g_sites[b.aid]=b}for(e in g_sites)if(g_sites[e].genpw&&g_sites[e].tld==b.tld&&lpmdec_acct(g_sites[e].password,true,g_sites[e],g_shares)==lpmdec_acct(b.password,true,b,g_shares)){typeof g_tlds[g_sites[e].tld]!="undefined"&&typeof g_tlds[g_sites[e].tld][e]!="undefined"&&
delete g_tlds[g_sites[e].tld][e];delete g_sites[e]}g_local_accts_version++;rewritelocalfile()}b=a[0].getAttribute("accts_version");compare_accounts_versions(b,g_local_accts_version)||get_accts();refresh_windows()}}}
function lpUpdateFieldsResponse(a,c,b){if(!rsa_shareeautopushesresponse(a,{url:b.posturl,aid:b.aid,postdata:b.postdata,handler:lpUpdateFieldsResponse,param:b,newvalues:b.newvalues}))if(a.readyState==4&&a.status==200&&a.responseXML&&a.responseXML.documentElement){a=a.responseXML.documentElement;c=a.getElementsByTagName("error");if(c.length>0)if((c=c[0].getAttribute("notloggedin"))&&c=="1"){loggedOut(false,"lpUpdateFieldsResponse");return}a=a.getElementsByTagName("ok");if(a.length>0){c=a[0].getAttribute("accts_version");
if(compare_accounts_versions(c,g_local_accts_version)){a=a[0].getAttribute("urid");c=b.urid=="0";var d=!c;if(c)b.urid=a;if(b.fields)for(var e=0;e<b.fields.length;e++)if(c&&!b.fields[e].otherfield&&b.fields[e].otherlogin!="1")b.fields[e].urid=a;else if(d&&!b.fields[e].otherfield&&b.fields[e].otherlogin=="1"&&b.fields[e].urid=="0")b.fields[e].urid=a}else get_accts();refresh_windows()}}}
function addNever(a){g_neverurls.neveraccounts.push(a);g_local_accts_version++;rewritelocalfile();a="url="+en(url2hex(a));lpMakeRequest(base_url+"add_never.php",a,null,null)}
function deleteGroup(a,c,b){if(issharedfolder(g_shares,a)!=false)alert("You cannot delete Shared folders.");else{var d="",e;for(e in g_sites)if(g_sites[e].group==a)d+=(d==""?"":",")+e;for(e in g_securenotes)if(g_securenotes[e].group==a)d+=(d==""?"":",")+e;for(e in g_applications)if(g_applications[e].group==a)d+=(d==""?"":",")+"app"+e;if(d=="")return deleteGroup("\\"+a,c,b);return deleteAid(d,c,false,false,b,a)}}
function checkmultiplefolders(a){for(var c=false,b=null,d=true,e=0;e<a.length;e++){var f=get_record(a[e]);if(f)if(issharedfolder(g_shares,f.group))if(c){d=false;break}else if(b==null)b=f.group;else{if(b!=f.group){d=false;break}}else if(b!=null){d=false;break}else c=true}d||alert(gs("Sorry, you cannot perform this operation on a mix of shared and non-shared folders, or multiple shared folders at once."));return d}
function deleteAid(a,c,b,d,e,f){var h=a.split(",");if(!checkmultiplefolders(h))return false;for(var k="",g=0,j=0;j<h.length;j++){var i=h[j];if(is_application(i)){if(!check_ident_appaid(i))continue}else if(!check_ident_aid(i))continue;var l,m;if(is_application(i)){l=get_record(i);m=false}else{l=g_sites[i];m=g_prompts.edit_site_prompt;if(!l){m=g_prompts.edit_sn_prompt;l=g_securenotes[i]}}if(l){k+=(k==""?"":",")+i;if(typeof l.sharefolderid!="undefined"){g=l.sharefolderid;i=issharedfolder(g_shares,l.group);
if(!checkreadonly(i))return false}if(!b&&(l.pwprotect||m)){security_prompt(function(){deleteAid(a,c,true,d,e)});return false}}}if(k=="")return false;j=gs("Are you sure you would like to delete this site?");if(l.genpw)j=gs("Are you sure you would like to delete this generated password?");else if(l.sn)j=gs("Are you sure you would like to delete this secure note?");else if(is_application(l))j=gs("Are you sure you would like to delete this application?");j+=" ("+l.name+")";if(h.length>1)j=gs("Are you sure you would like to delete the selected items?");
if(f)j=gs("Are you sure you would like to delete this group?")+" ("+f+")";if(!d)if(c==null){if(!g_isopera&&!confirm(j))return false}else if(!g_isopera&&!c.confirm(j))return false;f=k.split(",");for(j=0;j<f.length;j++){i=f[j];if(is_application(i))delete g_applications[get_appaid(i)];else{if(!l.sn)try{delete g_tlds[l.tld][i]}catch(n){}delete g_sites[i];delete g_securenotes[i]}}g_local_accts_version++;rewritelocalfile();k="ajax=1&extjs=1&delete=1&aid="+en(k);k+=get_identity_param();if(g!=0)k+="&sharedfolderid="+
en(g);lpMakeRequest(base_url+"show.php",k,lpDeleteResponse);e&&e();return true}function lpDeleteResponse(a){if(a)if(a.readyState==4&&a.status==200&&a.responseXML!=null&&a.responseXML.documentElement!=null){a=a.responseXML.documentElement.getElementsByTagName("result");if(a.length>0){a=a[0].getAttribute("accts_version");compare_accounts_versions(a,g_local_accts_version)||get_accts();refresh_windows()}}}
function editAid(a,c,b){if(check_ident_aid(a)){var d,e;if(is_application(a)){d=get_record(a);e=false}else{d=g_sites[a];e=g_prompts.edit_site_prompt;if(!d){e=g_prompts.edit_sn_prompt;d=g_securenotes[a]}}if(d)if(!b&&(d.pwprotect||e))security_prompt(function(){editAid(a,c,true)});else{g_site_data=[];for(var f in d)g_site_data[f]=d[f];openURL(getchromeurl("site.html"))}}}
function saveFields(a,c,b){b.handler=lpSaveFieldsResponse;if(typeof b.newvalues!="undefined"&&typeof b.newvalues.length=="undefined"){var d=b.newvalues,e=[],f;for(f in d)e.push(d[f]);b.newvalues=e}lpMakeRequest(base_url+"fields.php?"+a,c,lpSaveFieldsResponse,null,b)}
function lpSaveFieldsResponse(a,c,b){if(!(b!=null&&rsa_shareeautopushesresponse(a,b)))if(a.readyState==4&&a.status==200&&a.responseXML&&a.responseXML.documentElement){a=a.responseXML.documentElement;c=a.getElementsByTagName("response");if(c.length>0){c=c[0].getAttribute("message");console_log("Save Fields failed: "+c)}c=a.getElementsByTagName("error");if(c.length>0)if((c=c[0].getAttribute("notloggedin"))&&c=="1"){loggedOut(false,"lpSaveFieldsResponse");return}a=a.getElementsByTagName("result");if(a.length>
0){a=a[0].getAttribute("accts_version");compare_accounts_versions(a,g_local_accts_version)||get_accts();refresh_windows()}}}
function poll_server(){if(lploggedin&&grid_getdata("active")==null){var a=(new Date).getTime();g_lastpollcheck=a;if(lpGetPref("logoffWhenCloseBrowser",0)==1&&lpGetPref("logoffWhenCloseBrowserVal",0)>0){lpPutUserPref("lastpollcheck",g_lastpollcheck);lpWriteAllPrefs()}var c=parseInt(lpGetPref("pollServerVal",15))*60,b=c*1E3,d=function(e){if(e=="locked"||e=="idle")b*=g_logoff_other_ses?12:60;if(a-g_lastpoll>=b){lpMakeRequest(base_url+"poll_server.php","",poll_server_response,null);g_lastpoll=(new Date).getTime()}};
if(b>0)if(have_nplastpass()&&typeof g_nplastpass.get_idle_ms=="function"&&(typeof g_nplastpass.can_check_idle!="function"||g_nplastpass.can_check_idle())){c=g_nplastpass.get_idle_ms();d(c>=b?"idle":"active")}else enable_native_idle&&typeof chrome!="undefined"&&typeof chrome.idle!="undefined"?chrome.idle.queryState(c,d):d("active")}setTimeout("poll_server();",6E4)}var g_notifications=[];
function handlenotifications(a,c,b){lplog("notify: title="+a+" text="+c+" url="+b);if(webkitNotifications)if(webkitNotifications.checkPermission()!=0){lplog("notify: requesting permission");webkitNotifications.requestPermission(function(){lplog("notify: requesting permission callback called")})}else{var d=webkitNotifications.createNotification("images/icon48.png",a,c);if(d){var e=(new Date).getTime()+"_"+Math.floor(Math.random()*100);d.ondisplay=function(){lplog("notify: displaying notification id="+
e)};d.onclose=function(){lplog("notify: closing notification id="+e)};d.onclick=function(){lplog("notify: user clicked notification id="+e);if(b&&b!=""){lplog("notify: opening notication url for id="+e+" url="+b);d.cancel();openURL(b)}};d.show();g_notifications.push({id:e,time:(new Date).getTime(),note:d});g_notifications.length==1&&setTimeout("notifications_autoclose()",0)}else lplog("notify: error : failed to create notification")}else lplog("notify: error: webkitNotifications is null")}
function notifications_autoclose(){}function notifications_closeall(){lplog("notify: closing all notification");for(var a=0;a<g_notifications.length;++a){lplog("notify: closing notification id="+g_notifications[a].id);g_notifications[a].note.cancel()}g_notifications=[]}
function poll_server_response(a){if(4==a.readyState)if(a.status==200&&a.responseXML!=null&&a.responseXML.documentElement!=null){var c=a.responseXML.documentElement.getElementsByTagName("ok");if(c.length>0){g_logoff_other_ses=c[0].getAttribute("logoff_other_ses")=="1"?true:false;c[0].getAttribute("accts_version")>g_local_accts_version&&get_accts();if((a=c[0].getAttribute("note_title"))&&a.length){var b=c[0].getAttribute("note_text");c=c[0].hasAttribute("note_url")?c[0].getAttribute("note_url"):null;
handlenotifications(a,b,c)}}}else lpReportError("Problem in poll_server_response. status="+a.status,null)}
function upgrade_response(a){if(4==a.readyState)if(a.status==200&&a.responseXML!=null&&a.responseXML.documentElement!=null){a=a.responseXML.documentElement.getElementsByTagName("updatecheck");if(a.length>0){upgrade=a[0].getAttribute("upgrade")=="1"?true:false;upgradeurl=a[0].getAttribute("codebase");if(g_ischrome){g_notification_type="upgrade";g_notification_data={upgrade:upgrade,upgradeurl:upgradeurl};sendTS({cmd:"notification",type:"upgrade"})}else if(g_issafari||g_isopera)if(upgrade)confirm(gs("An Update is Available. Would you like to install?"))&&
openURL(upgradeurl);else alert(gs("No Updates Are Available"))}}else lpReportError("Problem in upgrade_response. status="+a.status,null)}
function changePassword(a,c){var b=[];b.push(a);for(var d=[],e=0,f=0;f<c.length;f++){if(lpmdec_acct(g_sites[c[f]].password,true,g_sites[c[f]],g_shares)!=a)d[d.length]=c[f];if(typeof g_sites[c[f]].sharefolderid!="undefined")e=g_sites[c[f]].sharefolderid}c=d;if(c.length!=0){d="xml=1";var h=[];for(f=0;f<c.length;f++){var k=f>0?f:"";d+="&username"+k+"=dummy";d+="&password"+k+"="+LP.en(lpenc_acct(a,g_sites[c[f]],g_shares));d+="&id"+k+"="+LP.en(c[f]);b.push(a);try{if(!lp_in_array(g_sites[c[f]].tld,h))h[h.length]=
g_sites[c[f]].tld}catch(g){}}try{for(f in g_sites)if(g_sites[f].genpw&&lp_in_array(g_sites[f].tld,h)&&lpmdec_acct(g_sites[f].password,true,g_sites[f],g_shares)==a){d+="&delgenpwaid="+LP.en(f);break}}catch(j){}if(e!=0)d+="&sharedfolderid="+en(e);e={};e.aid=0;e.postdata=d;e.url=base_url+"change_pw.php";e.newvalues=b;e.handler=lpChangePasswordResponse;e.param={aid:e.aid,postdata:e.postdata,url:e.url,newvalues:e.newvalues,handler:e.handler};lpMakeRequest(e.url,e.postdata,e.handler,null,e)}}
function lpChangePasswordResponse(a,c,b){if(!rsa_shareeautopushesresponse(a,b))if(a.readyState==4&&a.status==200&&a.responseXML&&a.responseXML.documentElement){a=a.responseXML.documentElement.getElementsByTagName("ok");if(a.length>0){c=crypto_atob(a[0].getAttribute("newpassword"));b=[];for(var d="";a[0].hasAttribute("oldpassword"+d);){var e=parseInt(a[0].getAttribute("id"+d)),f=crypto_atob(a[0].getAttribute("oldpassword"+d));e=g_sites[e];if(!lp_in_array(e.tld,b))b[b.length]=e.tld;if(e.password==f)e.password=
c;if(e.fields)for(var h=0;h<e.fields.length;h++)if(e.fields[h].type=="password"&&e.fields[h].value==f)e.fields[h].value=c;if(d=="")d=1;else d++}for(h in g_sites)if(g_sites[h].genpw&&lp_in_array(g_sites[h].tld,b)&&lpmdec_acct(g_sites[h].password,true,g_sites[h],g_shares)==lpmdec(c,true)){typeof g_tlds[g_sites[h].tld]!="undefined"&&typeof g_tlds[g_sites[h].tld][h]!="undefined"&&delete g_tlds[g_sites[h].tld][h];delete g_sites[h]}g_local_accts_version++;rewritelocalfile();h=a[0].getAttribute("accts_version");
compare_accounts_versions(h,g_local_accts_version)||get_accts()}}}var lpyubidata={};function yubikey_getotp(a){grid_setdata("active","1");lpdbg("yubikey","Asking user for fresh otp");a={otp:"",username:a};openURL(getchromeurl("lp_toolstrip.html?browseraction=1&yubikey=1"));return a.otp}function yubikey_setdata(a,c){lpyubidata[a]=c}function yubikey_getdata(a){if(typeof lpyubidata[a]=="undefined")return null;return lpyubidata[a]}
function yubikey_cleardata(){lpdbg("yubikey","clearing data");lpyubidata={}}
function yubikey_auth(a,c){grid_setdata("active",null);if(a!="")if(yubikey_getdata("offline")=="1"){var b=a.substring(0,12);a=SHA256(SHA256(SHA256(fix_username("LastPassIsGreat")+b)+b));yubikey_setdata("password_offline",a);offlineloginsuccessful("offline",0);lpReadAcctsData();yubikey_setdata("offline","0")}else{var d=b=null,e=null,f=null;if(yubikey_getdata("postdata")){b=yubikey_getdata("postdata")+"&otp="+encodeURIComponent(a);d="login.php";e=lpLoginResponse;f=lpLoginError}else{b=sesame_getdata("logincheckpostdata")+
"&otp="+encodeURIComponent(a);d="login_check.php";e=lpLoginCheckResponse;f=lpLoginCheckError}if(c!="")b+="&trustlabel="+encodeURIComponent(c);var h=sesame_getdata("fromwebsite");console_log("Requesting "+d+" C");lpMakeRequest(base_url+d,b,e,f,h)}else{lpshowError("LoginError",false,true);loggedOut(false,"yubikey_auth_error")}}var lpgoogleauthdata={};
function googleauth_getotp(a){grid_setdata("active","1");lpdbg("googleauth","Asking user for fresh otp");a={otp:"",username:a};openURL(getchromeurl("lp_toolstrip.html?browseraction=1&googleauth=1"));return a.otp}function googleauth_setdata(a,c){lpgoogleauthdata[a]=c}function googleauth_getdata(a){if(typeof lpgoogleauthdata[a]=="undefined")return null;return lpgoogleauthdata[a]}function googleauth_cleardata(){lpdbg("googleauth","clearing data");lpgoogleauthdata={}}
function googleauth_auth(a,c){grid_setdata("active",null);if(a!="")if(googleauth_getdata("offline")=="1"){var b=a.substring(0,12);a=SHA256(SHA256(SHA256(fix_username("LastPassIsGreat")+b)+b));googleauth_setdata("password_offline",a);offlineloginsuccessful("offline",0);lpReadAcctsData();googleauth_setdata("offline","0")}else{var d=b=null,e=null,f=null;if(googleauth_getdata("postdata")){b=googleauth_getdata("postdata")+"&otp="+encodeURIComponent(a);d="login.php";e=lpLoginResponse;f=lpLoginError}else{b=
sesame_getdata("logincheckpostdata")+"&otp="+encodeURIComponent(a);d="login_check.php";e=lpLoginCheckResponse;f=lpLoginCheckError}if(c!="")b+="&trustlabel="+encodeURIComponent(c);var h=sesame_getdata("fromwebsite");console_log("Requesting "+d+" C");lpMakeRequest(base_url+d,b,e,f,h)}else{lpshowError("LoginError",false,true);loggedOut(false,"googleauth_auth_error")}}var lpsesamedata={},lpsesameotp=null;
function sesame_setotp(a){lpdbg("sesame","browser forwarded OTP => sesame_setotp called");lpsesameotp=a}function sesame_getotp(a){grid_setdata("active","1");if(a&&lpsesameotp){lpdbg("sesame","Not requesting OTP - using value passed to browser");a=lpsesameotp;lpsesameotp=null;sesame_auth(a,"");return a}lpdbg("sesame","Asking user for fresh otp");a={otp:"",username:a};openURL(getchromeurl("lp_toolstrip.html?browseraction=1&sesame=1"));return a.otp}function sesame_setdata(a,c){lpsesamedata[a]=c}
function sesame_getdata(a){if(typeof lpsesamedata[a]=="undefined")return null;return lpsesamedata[a]}function sesame_cleardata(){lpdbg("sesame","clearing data");lpsesamedata={}}
function sesame_auth(a,c){grid_setdata("active",null);if(a!="")if(sesame_getdata("offline")=="1"){sesame_setdata("password_offline",a);offlineloginsuccessful("offline",0);lpReadAcctsData();sesame_setdata("offline","0")}else{var b=null,d=null,e=null,f=null;if(sesame_getdata("postdata")){b=sesame_getdata("postdata")+"&sesameotp="+encodeURIComponent(a);d="login.php";e=lpLoginResponse;f=lpLoginError}else{b=sesame_getdata("logincheckpostdata")+"&sesameotp="+encodeURIComponent(a);d="login_check.php";e=
lpLoginCheckResponse;f=lpLoginCheckError}if(c!="")b+="&trustlabel="+encodeURIComponent(c);var h=sesame_getdata("fromwebsite");console_log("Requesting "+d+" D");lpMakeRequest(base_url+d,b,e,f,h)}else{lpshowError("LoginError",false,true);loggedOut(false,"sesame_auth_error")}}var lpgriddata={},lpgridvalues=null;function grid_getvalues(a,c){grid_setdata("active","1");openURL(getchromeurl("lp_toolstrip.html?browseraction=1&grid=1&challenge="+encodeURIComponent(c)))}
function grid_setdata(a,c){lpgriddata[a]=c}function grid_getdata(a){if(typeof lpgriddata[a]=="undefined")return null;return lpgriddata[a]}function grid_cleardata(){lpdbg("grid","clearing data");lpgriddata={}}
function grid_auth(a,c){grid_setdata("active",null);if(a!=""){var b=null,d=null,e=null,f=null;if(grid_getdata("postdata")){b=grid_getdata("postdata")+"&gridresponse="+encodeURIComponent(a);d="login.php";e=lpLoginResponse;f=lpLoginError}else{b=sesame_getdata("logincheckpostdata")+"&gridresponse="+encodeURIComponent(a);d="login_check.php";e=lpLoginCheckResponse;f=lpLoginCheckError}if(c!="")b+="&trustlabel="+encodeURIComponent(c);if(grid_getdata("wxsessid"))b+="&wxsessid="+encodeURIComponent(grid_getdata("wxsessid"));
var h=grid_getdata("fromwebsite");console_log("Requesting "+d+" E");lpMakeRequest(base_url+d,b,e,f,h)}else{lpshowError("LoginError",false,true);loggedOut(false,"grid_auth_error")}}var lpmultifactordata={},lpmultifactorresponse=null;
function multifactor_getresponse(a,c){var b="";multifactor_setdata("active","1");var d=multifactor_getdata("type"),e="";if(multifactor_getdata("type")==d)e=multifactor_getdata("password_offline");if(!e||e.length!=64)e=SHA256(SHA256(fix_username(a)+d));if(!e||e.length!=64)if(d=="trueapi")if(have_nplastpass()&&typeof g_nplastpass.trueapi_get_hash=="function")e=g_nplastpass.trueapi_get_hash(a);multifactor_setdata("password_offline",e);multifactor_setdata("type",d);if(c)if(d=="omnikey"){omnikey_get_pin(function(f){if(have_nplastpass()&&
typeof g_nplastpass.omnikey_decrypt=="function")b=g_nplastpass.omnikey_decrypt(c,f);multifactor_auth(b,"")});return}else b=e!=""?SHA256(e+c):"";else b=e;multifactor_auth(b,"")}function multifactor_setdata(a,c){lpmultifactordata[a]=c}function multifactor_getdata(a){if(typeof lpmultifactordata[a]=="undefined")return null;return lpmultifactordata[a]}function multifactor_cleardata(){lpdbg("multifactor","clearing data");lpmultifactordata={}}
function multifactor_auth(a,c){multifactor_setdata("active",null);if(a!="")if(multifactor_getdata("offline")=="1"){multifactor_setdata("password_offline",a);multifactor_getdata("type")!="omnikey"&&multifactor_setdata("type","trueapi");offlineloginsuccessful("offline",0);lpReadAcctsData();multifactor_setdata("offline","0")}else{var b=null,d=null,e=null,f=null;if(multifactor_getdata("postdata")){b=multifactor_getdata("postdata")+"&multifactorresponse="+encodeURIComponent(a);d="login.php";e=lpLoginResponse;
f=lpLoginError}else{b=sesame_getdata("logincheckpostdata")+"&multifactorresponse="+encodeURIComponent(a);d="login_check.php";e=lpLoginCheckResponse;f=lpLoginCheckError}if(c!="")b+="&trustlabel="+encodeURIComponent(c);if(multifactor_getdata("wxsessid"))b+="&wxsessid="+encodeURIComponent(multifactor_getdata("wxsessid"));if(multifactor_getdata("type"))b+="&type="+encodeURIComponent(multifactor_getdata("type"));var h=multifactor_getdata("fromwebsite");console_log("Requesting "+d+" F");lpMakeRequest(base_url+
d,b,e,f,h)}else{lpshowError("LoginError",false,true,false,get_multifactor_disable_url(g_username,multifactor_getdata("type")));loggedOut(false,"multifactor_auth_error")}}
function lpSetupMultifactorResponse(a,c,b){if(4==a.readyState){if(200==a.status&&a.responseXML!=null&&a.responseXML.documentElement!=null){c=a.responseXML.documentElement.getElementsByTagName("ok");if(c.length>0){a=c[0].getAttribute("type");c=c[0].getAttribute("hash");if(a=="trueapi")if(typeof b.password!="undefined"){if(have_nplastpass()&&typeof g_nplastpass.trueapi_store_default_login=="function")if(g_nplastpass.trueapi_store_hash(g_username,c)){var d=b.silent=="1"?c:g_nplastpass.trueapi_get_hash(g_username);
if(d==c)if(g_nplastpass.trueapi_store_default_login(g_username,b.password,c)){setsinglefactortype(a);b.silent!="1"&&sendCS(b.tabid,{cmd:"setupsinglefactor",result:"done"},b.docnum);return}}}else{if(have_nplastpass()&&typeof g_nplastpass.trueapi_store_hash=="function")if(g_nplastpass.trueapi_store_hash(g_username,c)){d=b.silent=="1"?c:g_nplastpass.trueapi_get_hash(g_username);if(d==c&&b.silent!="1"){sendCS(b.tabid,{cmd:"setupmultifactor",result:"done"},b.docnum);return}}}else if(a=="vtapi"){if(have_nplastpass()&&
typeof g_nplastpass.lpvt_store_data=="function")if(g_nplastpass.lpvt_store_data(encodeURIComponent(g_username)+"|"+encodeURIComponent(b.password),gs("Swipe finger"),gs("Swipe your finger on the fingerprint sensor"),gs("Cancel"),gs("Swipe current user's finger"))){setsinglefactortype(a);b.silent!="1"&&sendCS(b.tabid,{cmd:"setupsinglefactor",result:"done"},b.docnum);return}}else if(a=="validity"){if(have_nplastpass()&&typeof g_nplastpass.validity_store_data=="function")if(g_nplastpass.validity_store_data(encodeURIComponent(g_username)+
"|"+encodeURIComponent(b.password),gs("Swipe finger"),gs("Swipe your finger on the fingerprint sensor"),gs("Cancel"))){setsinglefactortype(a);b.silent!="1"&&sendCS(b.tabid,{cmd:"setupsinglefactor",result:"done"},b.docnum);return}}else if(a=="winbio"){if(have_nplastpass()&&typeof g_nplastpass.winbio_store_data=="function")if(typeof g_nplastpass.winbio_has_fingerprints!="function"||g_nplastpass.winbio_has_fingerprints()){if(g_nplastpass.winbio_store_data(encodeURIComponent(g_username)+"|"+encodeURIComponent(b.password),
gs("Swipe finger"),gs("Swipe your finger on the fingerprint sensor"),gs("Cancel"))){setsinglefactortype(a);b.silent!="1"&&sendCS(b.tabid,{cmd:"setupsinglefactor",result:"done"},b.docnum);return}}else{typeof g_nplastpass.winbio_launch_enrollment=="function"&&g_nplastpass.winbio_launch_enrollment();b.silent!="1"&&sendCS(b.tabid,{cmd:"setupsinglefactor",result:"notenrolled"},b.docnum);return}}else if(a=="omnikey"){sendCS(b.tabid,{cmd:"setupsinglefactor",result:"done"},b.docnum);return}}}lpSetupMultifactorError(b)}}
function lpSetupMultifactorError(a){if(a.silent!=1)sendCS(a.tabid,{cmd:typeof a.password!="undefined"?"setupsinglefactor":"setupmultifactor",result:"error"},a.docnum)}function get_multifactor_disable_url(a,c){return"multifactordisable.php?cmd=sendemail&username="+en(a)+"&type="+en(c)}function lp_StartLogin(a){if(!g_loginstarted){g_loginstarted=true;if(a){rsa_setpendingsharests();lplogincheck("frompipes")}else httptest()}}
function can_chrome_do_math(){if((46512102&2600822924)!=33890436)return false;if(SHA256("testing")!="cf80cd8aed482d5d1527d7dc72fceff84e6326592848447d2dc0b0e87dfc9a90")return false;return true}
function lpDownloadDataResponse(a,c,b){if(a&&a.status==200&&a.readyState==4){c="";a=a.responseText.split("\n");for(var d=0;d<a.length;d++)if(a[d].indexOf("ff_")==0){var e=a[d].indexOf("=");if(e!=-1){var f=a[d].substr(0,e);e=a[d].substr(e+1);e=CheckStringForObfuscation(f,"",e);c+=f+"="+e+"\n"}}else c+=a[d]+"\n";localStorage.setItem(b,c);if(b=="ff.dat")ApplyAllOverrides();else b=="sites.dat"&&LoadSpecialSites()}}
function checkIterationsInDataFile(a){var c=get_key_iterations(g_username),b=a.substring(0,20);if(b.indexOf("iterations=")==0){b=/iterations=(\d*);/.exec(b);return b.length>1&&c==b[1]?a.substring(a.indexOf(";")+1):"iterationserror"}else{if(c!=1)return"iterationserror";return a}}function prependIterations(a){var c=get_key_iterations(g_username);if(c>1)a="iterations="+c+";"+a;return a};
