예제 #1
0
        public GeekUriComponents Sign(JObject data)
        {
            string nonceStr = RandomStringUtils.Random(10);

            string sign = geekSign.Sign(data, nonceStr, GetFullPath());

            this.queryParams = new Dictionary <string, string>();
            queryParams.Add("sign_type", geekSign.SignType);
            queryParams.Add("nonce_str", nonceStr);
            queryParams.Add("sign", sign);

            return(this);
        }
예제 #2
0
 /// <summary>Loads the memory to the target value.</summary>
 internal virtual void Load()
 {
     while (Runtime.GetRuntime().TotalMemory() < targetValue)
     {
         System.Console.Out.WriteLine("Loading memory with " + DefaultUnitLoadSize + " characters. Current usage : "
                                      + Runtime.GetRuntime().TotalMemory());
         // load some objects in the memory
         loadObjects.AddItem(RandomStringUtils.Random(DefaultUnitLoadSize));
         // sleep for 100ms
         try
         {
             Sharpen.Thread.Sleep(100);
         }
         catch (Exception)
         {
         }
     }
 }
예제 #3
0
        private string CreateAuthenticationDigest()
        {
            var ladanseApiSecret = _config["ladanse:api:secret"];

            var currentTimestamp = DateTimeOffset.Now.ToUnixTimeSeconds();

            var random = RandomStringUtils.Random(16);

            var toHash = random + ":" + currentTimestamp + ":" + ladanseApiSecret;

            var bytes = Encoding.UTF8.GetBytes(toHash);

            var sha256Managed = new SHA256Managed();

            var hash = sha256Managed.ComputeHash(bytes);

            var hashString = hash.Aggregate(string.Empty, (current, x) => current + string.Format("{0:x2}", x));

            return(random + ":" + currentTimestamp + ":" + hashString);
        }
예제 #4
0
        public static async Task GetToKnowUser(
            SocketCommandContext socketCommandContext,
            LaDanseUrlBuilder laDanseUrlBuilder,
            DiscordBotContext dbContext,
            DiscordUser discordUser)
        {
            #region CleanUpAuthSessions

            var authSessions = dbContext.AuthSessions
                               .Where(b => b.DiscordUser == discordUser)
                               .ToList();

            foreach (var authSession in authSessions)
            {
                if (authSession.State == AuthSessionState.Pending)
                {
                    authSession.State = AuthSessionState.Removed;
                }
            }

            #endregion

            #region NewAuthSession

            var newAuthSession = new AuthSession
            {
                Nonce       = RandomStringUtils.Random(32),
                CreatedOn   = 0,
                DiscordUser = discordUser,
                State       = AuthSessionState.Pending
            };

            dbContext.AuthSessions.Add(newAuthSession);

            #endregion

            await socketCommandContext.User.SendMessageAsync(
                "Click on this URL and follow the instructions if you want us to get to know each other better ...\n\n" +
                laDanseUrlBuilder.GetDiscordAuthInformUrl(newAuthSession.Nonce, "http://localhost:57077/connect/website"));
        }