示例#1
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            TwoFactorAuthenticator tfA = new TwoFactorAuthenticator();
            var result = tfA.ValidateTwoFactorPIN(txtSecretKey.Text, this.txtCode.Text);

            MessageBox.Show(result ? "Validated!" : "Incorrect", "Result");
        }
示例#2
0
        private void btnSetup_Click(object sender, EventArgs e)
        {
            TwoFactorAuthenticator tfA = new TwoFactorAuthenticator();
            var setupCode = tfA.GenerateSetupCode(this.txtAccountTitle.Text, this.txtSecretKey.Text, pbQR.Width, pbQR.Height);

            WebClient    wc = new WebClient();
            MemoryStream ms = new MemoryStream(wc.DownloadData(setupCode.QrCodeSetupImageUrl));

            this.pbQR.Image = Image.FromStream(ms);

            this.txtSetupCode.Text = "Account: " + setupCode.Account + System.Environment.NewLine +
                                     "Secret Key: " + setupCode.AccountSecretKey + System.Environment.NewLine +
                                     "Encoded Key: " + setupCode.ManualEntryKey;
        }
        public Boolean GenerateTwoFactorAuthentication()
        {
            Guid guid = Guid.NewGuid();
            //String uniqueUserKey = Convert.ToString(guid).Replace("-", "").Substring(0, 10);
            //String uniqueUserKey = "7b769307e9";
            //Store Key
            String uniqueUserKey = "Vinokurov";

            AuthenticationCode = uniqueUserKey;
            Dictionary <String, String> result = new Dictionary <String, String>();
            TwoFactorAuthenticator      tfa    = new TwoFactorAuthenticator();
            var setupInfo = tfa.GenerateSetupCode("USEND", AuthenticationTitle, AuthenticationCode, false, 5);

            if (setupInfo != null)
            {
                AuthenticationBarCodeImage = setupInfo.QrCodeSetupImageUrl;
                AuthenticationManualCode   = setupInfo.ManualEntryKey;
                return(true);
            }
            return(false);
        }
        public Boolean ValidateTwoFactorPIN(String pin)
        {
            TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();

            return(tfa.ValidateTwoFactorPIN(AuthenticationCode, pin));
        }