Exemplo n.º 1
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
        bool isCorrectPIN          = tfa.GetCurrentPIN("SuperSuperSuperSecretKeyGoesHere") == NameTextBox.Text;

        lblCheck.Text = isCorrectPIN.ToString();
    }
Exemplo n.º 2
0
        public IActionResult LoginTwoFactor(LoginTwoFactorVM model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Login"));
            }

            Korisnik korisnik = ctx.Korisnik
                                .SingleOrDefault(x => x.KorisnickoIme == model.username && x.LozinkaHash == PasswordSettings.GetHash(model.password, Convert.FromBase64String(x.LozinkaSalt)));

            if (korisnik == null)
            {
                ViewData["poruka"] = "Pogrešan username ili password";
                return(View("Login"));
            }


            TwoFactorAuthenticator TwoFacAuth = new TwoFactorAuthenticator();
            string current = TwoFacAuth.GetCurrentPIN(korisnik.TwoFactorUniqueKey);
            bool   isValid = current.Equals(model.TwoFactorPin);

            //bool isValid = true;
            if (isValid)
            {
                HttpContext.SetLogiraniKorisnik(korisnik, snimiUCookie: model.ZapamtiLozinku);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ViewData["poruka"] = "Pogrešan kod";
                return(View("LoginTwoFactor", model));
            }
        }
Exemplo n.º 3
0
        public Task <string> GenerateAsync(string purpose, UserManager <ApplicationUser, string> manager, ApplicationUser user)
        {
            //current code of user
            TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();

            return(Task.FromResult(tfa.GetCurrentPIN(user.GoogleAuthSecret)));
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                return;
            }

            TwoFactorAuthenticator tfa = new TwoFactorAuthenticator(true, true);

            Console.WriteLine("key: " + args[0]);

            //string[] pins = tfa.GetCurrentPINs(args[0]);

            //foreach (var s in pins)
            //    Console.WriteLine(s);

            Console.WriteLine(tfa.GetCurrentPIN(args[0]));

            //Console.ReadKey();

            //long counter = (long)(DateTime.UtcNow - UNIX_EPOCH).TotalSeconds / 30;
            //Console.WriteLine(GeneratePassword(args[0], counter));
            //Console.WriteLine(GeneratePassword(args[0].ToUpper(), counter));
            //Console.WriteLine(GeneratePassword(args[0].ToLower(), counter));
        }
Exemplo n.º 5
0
        public Task <bool> ValidateAsync(string purpose, string token, UserManager <ApplicationUser, string> manager, ApplicationUser user)
        {
            //validate userinput with current token with corresponding user secret
            TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();

            return(Task.FromResult(tfa.ValidateTwoFactorPIN(user.GoogleAuthSecret, tfa.GetCurrentPIN(user.GoogleAuthSecret))));
        }
        public void TestValidateTwoFactorPIN()
        {
            TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
            string securityKey         = RandomUtil.GetUniqueStr(10);
            string email = "test.bcsystech.com";

            var setupInfo = tfa.GenerateSetupCode("hopex.com", email, securityKey, 200, 200);

            Console.WriteLine(setupInfo.QrCodeSetupImageUrl);
            Console.WriteLine(setupInfo.ManualEntryKey);

            string pin = tfa.GetCurrentPIN(securityKey);

            Thread.Sleep(10 * 1000);
            bool ok = tfa.ValidateTwoFactorPIN(securityKey, tfa.GetCurrentPIN(securityKey));

            Assert.True(ok);
        }
 public bool ValidateTwoFactorPIN(string userID, string userPIN)
 {
     try
     {
         TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
         bool isCorrectPIN          = userPIN == tfa.GetCurrentPIN(userID);
         return(isCorrectPIN);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 8
0
        public ActionResult Verify2Fa()
        {
            var token         = Request["passcode"];
            var authenticator = new TwoFactorAuthenticator();
            var x             = authenticator.GetCurrentPIN(Key);
            var isValid       = authenticator.ValidateTwoFactorPIN(Key, token);

            if (isValid)
            {
                Session["IsValid2FA"] = true;
                return(RedirectToAction("UserProfile", "Home"));
            }
            return(RedirectToAction("Login", "Home"));
        }
        public static IEnumerable <object[]> GetPins()
        {
            var subject = new TwoFactorAuthenticator();

            yield return(new object[] { subject.GetCurrentPIN(secret), 2 });

            yield return(new object[] { subject.GetCurrentPIN(secret, DateTime.UtcNow), 3 });

            yield return(new object[] { subject.GetCurrentPIN(secretAsBytes), 4 });

            yield return(new object[] { subject.GetCurrentPIN(secretAsBytes, DateTime.UtcNow), 5 });

            yield return(new object[] { subject.GetCurrentPIN(secretAsBase32, true), 6 });

            yield return(new object[] { subject.GetCurrentPIN(secretAsBase32, DateTime.UtcNow, true), 7 });
        }
Exemplo n.º 10
0
    protected void Page_Load(object sender, EventArgs e)
    {
        TwoFactorAuthenticator tfa = new TwoFactorAuthenticator();
        var setupInfo  = tfa.GenerateSetupCode("MyApp", "*****@*****.**", "SuperSuperSuperSecretKeyGoesHere", 300, 300);
        var setupInfo2 = tfa.GetCurrentPIN("SuperSuperSuperSecretKeyGoesHere");

        lblSecretCode.Text = setupInfo2;
        string qrCodeImageUrl       = setupInfo.QrCodeSetupImageUrl;
        string manualEntrySetupCode = setupInfo.ManualEntryKey;
        bool   isCorrectPIN         = tfa.ValidateTwoFactorPIN("SuperSuperSuperSecretKeyGoesHere", setupInfo2);

        lblCheck.Text      = isCorrectPIN.ToString();
        imgQRcode.ImageUrl = qrCodeImageUrl;
        imgQRcode.Width    = 300;
        imgQRcode.Height   = 300;
        //if (Request.Cookies.Get("fingerprint") == null)
        //{
        //    HttpCookie cookie = new HttpCookie("fingerprint");
        //    cookie.Value = lblFingerprint.Text;
        //    DateTime dt = DateTime.Now;
        //    cookie.Expires = dt.AddDays(30);
        //    Response.Cookies.Add(cookie);
        //}
    }
Exemplo n.º 11
0
        public string GetCurrentPIN(string accountSecretKey)
        {
            var result = _authenticator.GetCurrentPIN(accountSecretKey);

            return(result);
        }
Exemplo n.º 12
0
        public object Any(Tocken request)
        {
            var tfa = new TwoFactorAuthenticator();

            return(tfa.GetCurrentPIN("ba6896eb43f547be8b476649a5ff43f3"));
        }