/// <summary>
        /// Generate the Secret
        /// </summary>
        /// <returns></returns>
        private async Task GenerateSecret()
        {
            var secret = await _userHelper.GenerateSecret();

            PayloadGenerator.OneTimePassword generator = new PayloadGenerator.OneTimePassword()
            {
                Secret = secret,
                Issuer = "AWS Cognito LDC 2021",
                Label  = User.Identity.Name,
            };
            string payload = generator.ToString();

            QRCodeGenerator qrGenerator = new QRCodeGenerator();
            QRCodeData      qrCodeData  = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q);
            QRCode          qrCode      = new QRCode(qrCodeData);

            //var qrCodeAsBitmap = qrCode.GetGraphic(20);
            using (var ms = new MemoryStream())
            {
                using (var image = qrCode.GetGraphic(20))
                {
                    image.Save(ms, ImageFormat.Png);
                    ViewBag.image = "data:image/png;base64," + Convert.ToBase64String(ms.ToArray());
                }
            }
        }
Example #2
0
        public void one_time_password_generator_time_based_generates_with_standard_options()
        {
            var pg = new PayloadGenerator.OneTimePassword
            {
                Secret = "pwq6 5q55",
                Issuer = "Google",
                Label  = "*****@*****.**",
            };

            pg.ToString().ShouldBe("otpauth://totp/Google:[email protected]?secret=pwq65q55&issuer=Google");
        }
Example #3
0
        public void one_time_password_generator_hmac_based_generates_with_standard_options()
        {
            var pg = new PayloadGenerator.OneTimePassword
            {
                Secret  = "pwq6 5q55",
                Issuer  = "Google",
                Label   = "*****@*****.**",
                Type    = PayloadGenerator.OneTimePassword.OneTimePasswordAuthType.HOTP,
                Counter = 500,
            };

            pg.ToString().ShouldBe("otpauth://hotp/Google:[email protected]?secret=pwq65q55&issuer=Google&counter=500");
        }