private static XDocument PerformSingleLoginRequest(string username,
                                                           string password,
                                                           int keyIterationCount,
                                                           NameValueCollection extraParameters,
                                                           ClientInfo clientInfo,
                                                           IWebClient webClient)
        {
            try
            {
                var parameters = new NameValueCollection
                {
                    { "method", PlatformToUserAgent[clientInfo.Platform] },
                    { "xml", "2" },
                    { "username", username },
                    { "hash", FetcherHelper.MakeHash(username, password, keyIterationCount) },
                    { "iterations", string.Format("{0}", keyIterationCount) },
                    { "includeprivatekeyenc", "1" },
                    { "outofbandsupported", "1" },
                    { "uuid", clientInfo.Id },
                    extraParameters
                };

                if (clientInfo.TrustThisDevice)
                {
                    parameters["trustlabel"] = clientInfo.Description;
                }

                return(XDocument.Parse(webClient.UploadValues("https://lastpass.com/login.php",
                                                              parameters).ToUtf8()));
            }
            catch (WebException e)
            {
                throw new LoginException(LoginException.FailureReason.WebException,
                                         "WebException occurred",
                                         e);
            }
            catch (XmlException e)
            {
                throw new LoginException(LoginException.FailureReason.InvalidResponse,
                                         "Invalid XML in response",
                                         e);
            }
        }
Beispiel #2
0
        private static XDocument Login(string username,
                                       string password,
                                       string multifactorPassword,
                                       int keyIterationCount,
                                       IWebClient webClient)
        {
            try
            {
                var parameters = new NameValueCollection
                {
                    { "method", "mobile" },
                    { "web", "1" },
                    { "xml", "1" },
                    { "username", username },
                    { "hash", FetcherHelper.MakeHash(username, password, keyIterationCount) },
                    { "iterations", string.Format("{0}", keyIterationCount) }
                };

                if (multifactorPassword != null)
                {
                    parameters["otp"] = multifactorPassword;
                }

                return(XDocument.Parse(webClient.UploadValues("https://lastpass.com/login.php",
                                                              parameters).ToUtf8()));
            }
            catch (WebException e)
            {
                throw new LoginException(LoginException.FailureReason.WebException,
                                         "WebException occured",
                                         e);
            }
            catch (XmlException e)
            {
                throw new LoginException(LoginException.FailureReason.InvalidResponse,
                                         "Invalid XML in response",
                                         e);
            }
        }