예제 #1
0
        private string EncryptPassword(string password, string modval, string expval)
        {
            var rsa       = new RSACryptoServiceProvider();
            var rsaParams = new RSAParameters
            {
                Modulus  = MarketUtils.StringToByteArray(modval),
                Exponent = MarketUtils.StringToByteArray(expval)
            };

            rsa.ImportParameters(rsaParams);
            var encodedPass = rsa.Encrypt(Encoding.ASCII.GetBytes(password), false);

            return(Convert.ToBase64String(encodedPass));
        }
예제 #2
0
        public AuthProcess Do(
            string login,
            string pass,
            string captchaGid  = null,
            string captchaText = null,
            string steamGuard  = null,
            string emailId     = null)
        {
            if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(pass))
            {
                throw new ArgumentException("Login or password must not be empty");
            }

            var auth = new AuthProcess();

            var rsa = this.GetRsa(login);

            if (!rsa.Success)
            {
                auth.Message = "Failed to get RSA";
                return(auth);
            }

            var encPass = this.EncryptPassword(pass, rsa.Module, rsa.Exponent);

            if (string.IsNullOrEmpty(encPass))
            {
                throw new SteamException("Failed to get encrypt password");
            }

            var @params = new Dictionary <string, string>
            {
                { "password", encPass },
                { "username", login },
                { "rsatimestamp", rsa.TimeStamp },
                { "remember_login", true.ToString() },
                { "loginfriendlyname", string.Empty },
                { "l", "en" }
            };

            if (!string.IsNullOrEmpty(captchaGid) && !string.IsNullOrEmpty(captchaText))
            {
                @params.Add("captchagid", captchaGid);
                @params.Add("captcha_text", captchaText);
            }
            else
            {
                @params.Add("captchagid", "-1");
                @params.Add("captcha_text", null);
            }

            if (!string.IsNullOrEmpty(steamGuard) && !string.IsNullOrEmpty(emailId))
            {
                @params.Add("emailsteamid", emailId);
                @params.Add("emailauth", steamGuard);
            }
            else if (!string.IsNullOrEmpty(steamGuard))
            {
                @params.Add("twofactorcode", steamGuard);
            }

            var resp  = this._steam.Request(Urls.LoginDo, Method.POST, Urls.Login, @params);
            var jresp = JsonConvert.DeserializeObject <JLogin>(resp.Data.Content);

            auth.Message = jresp.Message;

            if (jresp.Success)
            {
                this.IsAuthorized    = true;
                this.CookieContainer = resp.CookieContainer;
                auth.Success         = true;
                return(auth);
            }

            if (jresp.CaptchaNeeded)
            {
                auth.CaptchaNeeded   = true;
                auth.CaptchaGid      = jresp.CaptchaGid;
                auth.CaptchaImageUrl = MarketUtils.GetCaptchaImageUrl(jresp.CaptchaGid);
            }

            if (jresp.EmailAuthNeeded)
            {
                auth.EmailAuthNeeded = true;
                auth.EmailId         = jresp.EmailId;
            }
            else if (jresp.RequiresTwoFactor)
            {
                auth.TwoFactorNeeded = true;
            }

            return(auth);
        }