Exemple #1
0
 /// <summary>
 /// Returns true if the auth token is still valid
 /// 2/2017 ignoring expiry on token since user can logout
 /// </summary>
 public bool ValidateAuthToken(string token)
 {
     if (TokenList == null)
     {
         return(false);
     }
     return(TokenList.ContainsKey(token));// && TokenList[token].CompareTo(DateTime.UtcNow) >= 0;
 }
Exemple #2
0
        public static bool ValidateToken(string username)
        {
            if (!TokenList.ContainsKey(username))
            {
                return(false);
            }
            KODevelopersLoginResponse loginResponse = new KODevelopersLoginResponse();

            using (WebClient client = new WebClient())
            {
                client.Headers["Content-Type"] = "application/x-www-form-urlencoded";
                client.Headers["user-agent"]   = "Microsoft URL Control";
                System.Collections.Specialized.NameValueCollection postData =
                    new System.Collections.Specialized.NameValueCollection()
                {
                    { "uid", EncryptString(username, key, iv) },
                    { "pwd", EncryptString(TokenList[username], key, iv) },
                    { "app", EncryptString(application_name, key, iv) },
                    { "ver", EncryptString(application_version, key, iv) },
                    { "meth", EncryptString("TOKEN", key, iv) }
                };
                string response = Encoding.UTF8.GetString(client.UploadValues(script_url, postData));
                Dictionary <string, object> jsonFields = JObject.Parse(response.TrimEnd().TrimStart()).ToObject <Dictionary <string, object> >();
                foreach (var v in jsonFields)
                {
                    switch (v.Key)
                    {
                    case "result":
                        loginResponse.Result = DecryptString(v.Value as string, key, iv);
                        break;

                    case "message":
                        loginResponse.Message = v.Value as string;
                        break;

                    case "token":
                        loginResponse.EncryptedToken = v.Value as string;
                        loginResponse.PlainToken     = DecryptString(v.Value as string, key, iv);
                        break;
                    }
                }
                if (loginResponse.Result.Substring(0, 29) == "LS002RvkzvsDWeLdGDGCKHDKx8SuP")
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #3
0
        public static KODevelopersLoginResponse Login(string username, string password)
        {
            if (!init)
            {
                SHA256 mySHA256 = SHA256Managed.Create();
                key = mySHA256.ComputeHash(Encoding.ASCII.GetBytes("Q3QgesV4wMug5ZtS7DenWAw3"));

                iv = new byte[16] {
                    0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0
                };
                init = true;
                LoadTokenList(); // Eğer daha önceden kayıtlı token varsa yükle
            }
            KODevelopersLoginResponse loginResponse = new KODevelopersLoginResponse();

            using (WebClient client = new WebClient())
            {
                retokenize_me :;
                client.Headers["Content-Type"] = "application/x-www-form-urlencoded";
                client.Headers["user-agent"]   = "Microsoft URL Control";

                //client.Headers["Connection"] = "Keep-alive";
                System.Collections.Specialized.NameValueCollection postData;
                if (TokenList.ContainsKey(username))
                {
                    postData = new System.Collections.Specialized.NameValueCollection()
                    {
                        { "uid", EncryptString(username, key, iv) },
                        { "pwd", EncryptString(TokenList[username], key, iv) },
                        { "app", EncryptString(application_name, key, iv) },
                        { "ver", EncryptString(application_version, key, iv) },
                        { "meth", EncryptString("TOKEN", key, iv) }
                    };
                }
                else
                {
                    postData = new System.Collections.Specialized.NameValueCollection()
                    {
                        { "uid", EncryptString(username, key, iv) },
                        { "pwd", EncryptString(password, key, iv) },
                        { "app", EncryptString(application_name, key, iv) },
                        { "ver", EncryptString(application_version, key, iv) },
                        { "meth", EncryptString("PASSWORD", key, iv) }
                    };
                }

                string response = Encoding.UTF8.GetString(client.UploadValues(script_url, postData));
                Dictionary <string, object> jsonFields = JObject.Parse(response.TrimEnd().TrimStart()).ToObject <Dictionary <string, object> >();
                foreach (var v in jsonFields)
                {
                    switch (v.Key)
                    {
                    case "result":
                        loginResponse.Result = DecryptString(v.Value as string, key, iv);
                        break;

                    case "message":
                        loginResponse.Message = v.Value as string;
                        break;

                    case "token":
                        loginResponse.EncryptedToken = v.Value as string;
                        loginResponse.PlainToken     = DecryptString(v.Value as string, key, iv);
                        break;
                    }
                }

                switch (loginResponse.Result.Substring(0, 29))
                {
                case "LS001Gs84DmanHUWmrWwLgDKysrFk":
                    break;

                case "LS002RvkzvsDWeLdGDGCKHDKx8SuP":
                    break;

                case "LS003F5esRwzAPt33psnJdEt7eJkT":
                    TokenList.Remove(username);     // Expired token removal
                    SaveTokenList();
                    goto retokenize_me;

                case "LS004GUcuNEM67D2P5PbUXqTLPHTt":
                    TokenList.Remove(username);     // Invalid token removal
                    SaveTokenList();
                    break;

                case "LS004rPrCHnnYLHUREjrh2fUggjQJ":
                    break;

                case "LS00TF5esRwzAPt33psnJdEt7eJkT":
                    TokenList.Add(username, loginResponse.EncryptedToken);
                    SaveTokenList();
                    break;

                case "LS00Ef9TV4vPbmGh9tytn7HdTMZp2":
                    break;
                }
            }
            return(loginResponse);
        }