Ejemplo n.º 1
0
        public async Task <IActionResult> Captcha()
        {
            string captchaCode = ImageFactory.CreateCode(LoginVM.CAPTCHA_CODE_LENGTH);
            await HttpContext.Session.LoadAsync();

            HttpContext.Session.SetString(CAPTCHA, captchaCode);
            using var stream = ImageFactory.BuildImage(captchaCode, 50, 100, 20, 3);
            return(Ok("data:image/jpeg; base64, " + Convert.ToBase64String(stream.ToArray())));
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            string code = ImageFactory.CreateCode(5);

            using (FileStream fs = File.OpenWrite("d:/1.jpg"))
                using (Stream picStream = ImageFactory.BuildImage(code, 50, 100, 20, 10))
                {
                    picStream.CopyTo(fs);
                }
            //Console.ReadKey();
        }
Ejemplo n.º 3
0
        public static async Task SendCaptchaAsync(SocketUser u)
        {
            string captchaCode = ImageFactory.CreateCode(6);

            await Task.Yield();

            Task         save        = verificationDatabase.Captcha.SetCaptchaAsync(captchaCode, u);
            MemoryStream imageStream = ImageFactory.BuildImage(captchaCode, 60, 160, 24, 14);

            imageStream.Position = 0;

            Image image = Image.FromStream(imageStream);

            image.Save($"{u.Id}.png", ImageFormat.Png);

            await Task.WhenAll
            (
                save,
                u.SendFileAsync($"{u.Id}.png", $"Please type `\\verify` followed by a space and this captcha code to continue{((u as SocketGuildUser) != null ? $" to {(u as SocketGuildUser)!.Guild.Name}" : "")}.\n")
            );

            image.Dispose();
            File.Delete($"{u.Id}.png");

            List <Task> commands = new();

            foreach (SocketGuild g in u.MutualGuilds)
            {
                if (await verificationDatabase.Roles.GetVerificationRoleAsync(g) == null)
                {
                    continue;
                }
                SocketGuildUser user = g.GetUser(u.Id);
                commands.Add(SendToCaptchaLog.SendToCaptchaLogAsync(SendToCaptchaLog.CaptchaType.Requested, user, captchaCode));
            }
            await Task.WhenAll(commands);
        }