Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# &引用;您输入的帐户名或密码不正确";蒸汽Api错误_C#_.net_Steam - Fatal编程技术网

C# &引用;您输入的帐户名或密码不正确";蒸汽Api错误

C# &引用;您输入的帐户名或密码不正确";蒸汽Api错误,c#,.net,steam,C#,.net,Steam,我收到“您输入的帐户名或密码不正确”尝试使用此api端点登录时出错: 我使用的是通过Steam应用程序或Steam web登录时使用的凭据,因此我认为我的凭据没有问题 下面是我使用的代码: public bool DoLogin(string username, string password) { var data = new NameValueCollection { { "username", username } }; // First get the RSA key w

我收到“您输入的帐户名或密码不正确”尝试使用此api端点登录时出错:

我使用的是通过Steam应用程序或Steam web登录时使用的凭据,因此我认为我的凭据没有问题

下面是我使用的代码:

public bool DoLogin(string username, string password)
{
    var data = new NameValueCollection { { "username", username } };
    // First get the RSA key with which we will encrypt our password.
    string response = Fetch("https://steamcommunity.com/login/getrsakey", "POST", data, false);
    GetRsaKey rsaJson = JsonConvert.DeserializeObject<GetRsaKey>(response);

    // Validate, if we could get the rsa key.
    if (!rsaJson.success)
    {
        return false;
    }

    // RSA Encryption.
    RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
    RSAParameters rsaParameters = new RSAParameters
    {
        Exponent = HexToByte(rsaJson.publickey_exp),
        Modulus = HexToByte(rsaJson.publickey_mod)
    };

    rsa.ImportParameters(rsaParameters);

    // Encrypt the password and convert it.
    byte[] bytePassword = Encoding.ASCII.GetBytes(password);
    byte[] encodedPassword = rsa.Encrypt(bytePassword, false);
    string encryptedBase64Password = Convert.ToBase64String(encodedPassword);

    SteamResult loginJson = null;
    CookieCollection cookieCollection;
    string steamGuardText = "";
    string steamGuardId = "";

    // Do this while we need a captcha or need email authentification. Probably you have misstyped the captcha or the SteamGaurd code if this comes multiple times.
    do
    {
        Console.WriteLine("SteamWeb: Logging In...");

        bool captcha = loginJson != null && loginJson.captcha_needed;
        bool steamGuard = loginJson != null && loginJson.emailauth_needed;

        string time = Uri.EscapeDataString(rsaJson.timestamp);

        string capGid = string.Empty;
        // Response does not need to send if captcha is needed or not.
        // ReSharper disable once MergeSequentialChecks
        if (loginJson != null && loginJson.captcha_gid != null)
        {
            capGid = Uri.EscapeDataString(loginJson.captcha_gid);
        }

        data = new NameValueCollection { { "password", encryptedBase64Password }, { "username", username } };

        // Captcha Check.
        string capText = "";
        if (captcha)
        {
            Console.WriteLine("SteamWeb: Captcha is needed.");
            System.Diagnostics.Process.Start("https://steamcommunity.com/public/captcha.php?gid=" + loginJson.captcha_gid);
            Console.WriteLine("SteamWeb: Type the captcha:");
            string consoleText = Console.ReadLine();
            if (!string.IsNullOrEmpty(consoleText))
            {
                capText = Uri.EscapeDataString(consoleText);
            }
        }

        data.Add("captchagid", captcha ? capGid : "-1");
        data.Add("captcha_text", captcha ? capText : "");
        // Captcha end.
        // Added Header for two factor code.
        data.Add("twofactorcode", "");

        // Added Header for remember login. It can also set to true.
        data.Add("remember_login", "false");

        // SteamGuard check. If SteamGuard is enabled you need to enter it. Care probably you need to wait 7 days to trade.
        // For further information about SteamGuard see: https://support.steampowered.com/kb_article.php?ref=4020-ALZM-5519&l=english.
        if (steamGuard)
        {
            Console.WriteLine("SteamWeb: SteamGuard is needed.");
            Console.WriteLine("SteamWeb: Type the code:");
            string consoleText = Console.ReadLine();
            if (!string.IsNullOrEmpty(consoleText))
            {
                steamGuardText = Uri.EscapeDataString(consoleText);
            }
            steamGuardId = loginJson.emailsteamid;

            // Adding the machine name to the NameValueCollection, because it is requested by steam.
            Console.WriteLine("SteamWeb: Type your machine name:");
            consoleText = Console.ReadLine();
            var machineName = string.IsNullOrEmpty(consoleText) ? "" : Uri.EscapeDataString(consoleText);
            data.Add("loginfriendlyname", machineName != "" ? machineName : "defaultSteamBotMachine");
        }

        data.Add("emailauth", steamGuardText);
        data.Add("emailsteamid", steamGuardId);
        // SteamGuard end.

        // Added unixTimestamp. It is included in the request normally.
        var unixTimestamp = (int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
        // Added three "0"'s because Steam has a weird unix timestamp interpretation.
        data.Add("donotcache", unixTimestamp + "000");

        data.Add("rsatimestamp", time);

        // Sending the actual login.
        using (HttpWebResponse webResponse = Request("https://steamcommunity.com/login/dologin/", "POST", data, false))
        {
            var stream = webResponse.GetResponseStream();
            if (stream == null)
            {
                return false;
            }
            using (StreamReader reader = new StreamReader(stream))
            {
                string json = reader.ReadToEnd();
                loginJson = JsonConvert.DeserializeObject<SteamResult>(json);
                cookieCollection = webResponse.Cookies;
            }
        }
    } while (loginJson.captcha_needed || loginJson.emailauth_needed);

    // If the login was successful, we need to enter the cookies to steam.
    if (loginJson.success)
    {
        _cookies = new CookieContainer();
        foreach (Cookie cookie in cookieCollection)
        {
            _cookies.Add(cookie);
        }
        SubmitCookies(_cookies);
        return true;
    }
    else
    {
        Console.WriteLine("SteamWeb Error: " + loginJson.message);
        return false;
    }

}
public bool DoLogin(字符串用户名、字符串密码)
{
var data=newnamevalueCollection{{“username”,username};
//首先获取RSA密钥,我们将使用该密钥加密密码。
字符串响应=获取(“https://steamcommunity.com/login/getrsakey“,”后“,数据,假);
GetRsaKey rsaJson=JsonConvert.DeserializeObject(响应);
//验证,如果我们能得到rsa密钥。
如果(!rsaJson.success)
{
返回false;
}
//RSA加密。
RSACryptoServiceProvider rsa=新的RSACryptoServiceProvider();
RSAPERAMETERS RSAPERAMETERS=新的RSAPERAMETERS
{
指数=HexToByte(rsaJson.publickey_exp),
模数=十六字节(rsaJson.publickey_mod)
};
rsa.输入参数(rsa参数);
//加密密码并转换它。
byte[]bytePassword=Encoding.ASCII.GetBytes(密码);
字节[]encodedPassword=rsa.Encrypt(bytePassword,false);
string encryptedBase64Password=Convert.ToBase64String(encodedPassword);
streamresult loginJson=null;
CookieCollection CookieCollection;
字符串steamGuardText=“”;
字符串“=”;
//在我们需要验证码或电子邮件身份验证时执行此操作。如果多次出现验证码或SteamGaurd代码,则可能是您键入了错误的验证码或SteamGaurd代码。
做
{
Console.WriteLine(“SteamWeb:登录…”);
bool captcha=loginJson!=null&&loginJson.captcha\u需要;
bool-steamGuard=loginJson!=null&&loginJson.emailauth\u需要;
string time=Uri.EscapeDataString(rsaJson.timestamp);
string capGid=string.Empty;
//如果需要或不需要验证码,则无需发送响应。
//ReSharper禁用一次合并顺序检查
if(loginJson!=null&&loginJson.captcha\u gid!=null)
{
capGid=Uri.EscapeDataString(loginJson.captcha_-gid);
}
数据=新名称值集合{{“密码”,encryptedBase64Password},{“用户名”,用户名};
//验证码检查。
字符串capText=“”;
如果(验证码)
{
WriteLine(需要验证码);
系统.诊断.进程.启动(“https://steamcommunity.com/public/captcha.php?gid=“+loginJson.captcha_gid);
WriteLine(“SteamWeb:键入验证码:”);
字符串consoleText=Console.ReadLine();
如果(!string.IsNullOrEmpty(consoleText))
{
capText=Uri.EscapeDataString(控制台文本);
}
}
数据。添加(“captchagid”,captcha?capGid:“-1”);
添加(“验证码文本”,验证码?验证码文本:“”);
//验证码结束。
//添加了双因素代码的标题。
添加(“twofactorcode”和“);
//为记住登录添加了标题。它也可以设置为true。
添加(“记住登录”、“错误”);
//SteamGuard检查。如果启用了SteamGuard,您需要输入它。请注意,您可能需要等待7天才能进行交易。
//有关SteamGuard的更多信息,请参阅:https://support.steampowered.com/kb_article.php?ref=4020-ALZM-5519&l=英语。
if(蒸汽防护)
{
控制台。WriteLine(“需要SteamWeb:SteamGuard”);
WriteLine(“SteamWeb:键入代码:”);
字符串consoleText=Console.ReadLine();
如果(!string.IsNullOrEmpty(consoleText))
{
steamGuardText=Uri.EscapeDataString(consoleText);
}
steamGuardId=loginJson.emailsteamid;
//将计算机名称添加到NameValueCollection,因为它是由steam请求的。
WriteLine(“SteamWeb:键入您的机器名:”);
consoleText=Console.ReadLine();
var machineName=string.IsNullOrEmpty(consoleText)?“”:Uri.EscapeDataString(consoleText);
data.Add(“loginfriendlyname”,machineName!=”?machineName:“defaultSteamBotMachine”);
}
添加(“emailauth”,steamGuardText);
添加(“emailsteamid”,steamGuardId);
//蒸汽防护端。
//添加了unixTimestamp。它通常包含在请求中。
var unixtimestap=(int)(DateTime.UtcNow.Subtract(newdatetime(1970,1,1))).TotalSeconds;
//添加了三个“0”,因为Steam有一个奇怪的unix时间戳解释。
添加(“donotcache”,unixTimestamp+“000”);
添加(“RSA时间戳”,时间);
//发送实际登录名。
使用(HttpWebResponse webResponse=Request(“https://steamcommunity.com/login/dologin/“,”后“,数据,假”)
{
var stream=webResponse.GetResponseStream();
if(流==null)
{
返回false;
}
使用(StreamReader=新StreamReader(stream))
{
字符串json=reader.ReadToEnd();
loginJson=JsonConvert.DeserializeObject(json);
cookieCollection=webResponse.Cookies;
}
}
}while(loginJson.captcha|u需要| | loginJson.emailauth|u需要);
//如果登录成功,我们需要输入cookies以进行steam。
if(loginJson.success)
{
_cookies=新CookieContainer();
foreach(cookieCollection中的Cookie Cookie)
{
_添加(cookie);
}
提交的文件(_cookies);
返回true;
}
其他的
{
Console.WriteLine(“SteamWeb错误:+loginJson.message”);
返回false;
}
}

有吗
 private IRestClient restClientTemporary;
 private string getKeysURL = "/login/getrsakey/";
 private string loginWithKey = "/login/dologin/";
restClientTemporary = new RestClient("https://steamcommunity.com");
var request = new RestRequest(getKeysURL, Method.POST);
request.AddParameter("username", "YourSteamLogin");

var resp = restClientTemporary.Execute(request);
GetRsaResult response = Newtonsoft.Json.JsonConvert.DeserializeObject<GetRsaResult>(resp.Content);

    public static string EncryptionSof(string password, GetRsaResult response)
        {
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
            RSAParameters rsaParameters = new RSAParameters
            {
                Exponent = HexToByte(response.publickey_exp),
                Modulus = HexToByte(response.publickey_mod)
            };

            rsa.ImportParameters(rsaParameters);

            // Encrypt the password and convert it.
            byte[] bytePassword = Encoding.ASCII.GetBytes(password);
            byte[] encodedPassword = rsa.Encrypt(bytePassword, false);
            return Convert.ToBase64String(encodedPassword);
        }

string password = EncryptionSof("admin123/*its your steam password i think*/", response);
var loginRequest = new RestRequest(loginWithKey);
loginRequest.AddParameter("username", "YourSteamLogin");
loginRequest.AddParameter("password", password);
loginRequest.AddParameter("rsatimestamp", response.timestamp);
loginRequest.AddParameter("remember_login", false);
//Captcha stuff if needed:
loginRequest.AddParameter("captchagid", 3086601225255895896);
loginRequest.AddParameter("captcha_text", "LHYJ2P");

var responseFinal = restClientTemporary.Execute(loginRequest);
{
   "success":true,
   "requires_twofactor":false,
   "login_complete":true,
   "transfer_urls":[
      "https:\\/\\/store.steampowered.com\\/login\\/transfer",
      "https:\\/\\/help.steampowered.com\\/login\\/transfer"
   ],
   "transfer_parameters":{
      "steamid":"12344567898765432",
      "token_secure":"xDDDDDDDDD",
      "auth":"LOOOOOL",
      "remember_login":false
   }
}

    public class GetRsaResult
    {
        public bool success { get; set; }
        public string publickey_mod { get; set; }
        public string publickey_exp { get; set; }
        public string timestamp { get; set; }
        public string token_gid { get; set; }
    }
public static byte[] HexToByte(string hex)
        {
            return Enumerable.Range(0, hex.Length)
                             .Where(x => x % 2 == 0)
                             .Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
                             .ToArray();
        }