Пример #1
0
        public void AttemptsTest()
        {
            List <Card> cards = new List <Card>();

            /*Card 1*/
            Card one = new Card();

            one.CardNumber = "12345";
            one.Pin        = "2244";

            /*Add cards to the list*/
            cards.Add(one);

            for (int i = 0; i < cards.Count; i = i + 1)
            {
                cards[i].PasswordAttempts = 3;
            }

            BankAuthentication auth = new BankAuthentication(cards);

            auth.Authenticate("12345", "0010");
            auth.Authenticate("12345", "0010");
            auth.Authenticate("12345", "0010");

            Assert.AreEqual(auth.Authenticate("12345", "2244"), false);
        }
Пример #2
0
        public ActionResult Authenticate(AuthenticateCardModel model)
        {
            var result  = security.Authenticate(model.CardNumber, model.Pin);
            var attemps = security.Attempts(model.CardNumber);

            switch (result)
            {
            case true:
                Session["CardNumber"] = model.CardNumber;
                return(Json(new { result = result, attempts = attemps }, JsonRequestBehavior.AllowGet));

            default:
                ModelState.AddModelError("", "Failed to authenticate");
                return(Json(new { result = result, attempts = attemps }, JsonRequestBehavior.AllowGet));
            }
        }
Пример #3
0
        public void WrongUsernameTest()
        {
            List <Card> cards = new List <Card>();

            /*Card 1*/
            Card one = new Card();

            one.CardNumber = "12345";
            one.Pin        = "2244";

            /*Card 2*/
            Card two = new Card();

            two.CardNumber = "24680";
            two.Pin        = "0011";

            /*Card 3*/
            Card three = new Card();

            three.CardNumber = "98765";
            three.Pin        = "2468";

            /*Add cards to the list*/
            cards.Add(one);
            cards.Add(two);
            cards.Add(three);

            for (int i = 0; i < cards.Count; i = i + 1)
            {
                cards[i].PasswordAttempts = 3;
            }

            BankAuthentication auth = new BankAuthentication(cards);

            Assert.AreEqual(auth.Authenticate("10101", "0011"), false);
        }