Пример #1
0
        public void AddFailedLoginAttemptTest()
        {
            Security security = new Security(5,5);

            string logString = "la=2;dt=" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string newLogString = security.AddFailedLoginAttempt(logString);
            Assert.IsTrue(newLogString.StartsWith("la=3;"));

            logString = "la=0;dt=" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            newLogString = security.AddFailedLoginAttempt(logString);
            Assert.IsTrue(newLogString.StartsWith("la=1;"));

            logString = "la=2;dt=" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd HH:mm:ss");
            newLogString = security.AddFailedLoginAttempt(logString);
            Assert.IsTrue(newLogString.StartsWith("la=1;"));

            logString = "la=4;dt=" + DateTime.Now.AddYears(-1).ToString("yyyy-MM-dd HH:mm:ss");
            newLogString = security.AddFailedLoginAttempt(logString);
            Assert.IsTrue(newLogString.StartsWith("la=1;"));

            logString = "la=2;dt=" + DateTime.Now.AddHours(-1).ToString("yyyy-MM-dd HH:mm:ss");
            newLogString = security.AddFailedLoginAttempt(logString);
            Assert.IsFalse(newLogString.StartsWith("la=3;") && newLogString.Contains(DateTime.Now.Hour.ToString()));

            logString = "la=0;dt=" + DateTime.Now.AddDays(2).ToString("yyyy-MM-dd HH:mm:ss");
            newLogString = security.AddFailedLoginAttempt(logString);
            Assert.IsTrue(newLogString.StartsWith("la=1;") && newLogString.Contains(DateTime.Now.Hour.ToString()) && newLogString.Contains(DateTime.Now.Day.ToString()));

            logString = "la=2;dt=" + DateTime.Now.AddMinutes(-1).ToString("yyyy-MM-dd HH:mm:ss");
            newLogString = security.AddFailedLoginAttempt(logString);
            Assert.IsTrue(newLogString.StartsWith("la=3;"));

            logString = "la=2;dt=" + DateTime.Now.AddMinutes(-6).ToString("yyyy-MM-dd HH:mm:ss");
            newLogString = security.AddFailedLoginAttempt(logString);
            Assert.IsTrue(newLogString.StartsWith("la=1;"));

            logString = "";
            newLogString = security.AddFailedLoginAttempt(logString);
            Assert.IsTrue(newLogString.StartsWith("la=1;"));

            logString = null;
            newLogString = security.AddFailedLoginAttempt(logString);
            Assert.IsTrue(newLogString.StartsWith("la=1;"));
        }
Пример #2
0
        public void AllowLoginTest()
        {
            string logString = "la=2;dt="+ DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            Security security = new Security(5, 5);
            Assert.IsTrue(security.AllowLogin(logString));

            logString = "la=1;dt=" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            Assert.IsTrue(security.AllowLogin(logString));

            logString = "la=100;dt=" + DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
            Assert.IsTrue(security.AllowLogin(logString));

            logString = "la=100;dt=" + DateTime.Now.AddYears(-1).ToString("yyyy-MM-dd HH:mm:ss");
            Assert.IsTrue(security.AllowLogin(logString));

            logString = "la=100;dt=" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            Assert.IsFalse(security.AllowLogin(logString));

            logString = "la=11;dt=" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            Assert.IsFalse(security.AllowLogin(logString));

            logString = "la=6;dt=" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            Assert.IsFalse(security.AllowLogin(logString));

            logString = "la=5;dt=" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            Assert.IsFalse(security.AllowLogin(logString));

            logString = "la=5;dt=" + DateTime.Now.AddMinutes(-3).ToString("yyyy-MM-dd HH:mm:ss");
            Assert.IsFalse(security.AllowLogin(logString));

            logString = "la=5;dt=" + DateTime.Now.AddMinutes(-6).ToString("yyyy-MM-dd HH:mm:ss");
            Assert.IsTrue(security.AllowLogin(logString));

            logString = "";
            Assert.IsTrue(security.AllowLogin(logString));

            logString = null;
            Assert.IsTrue(security.AllowLogin(logString));
        }
Пример #3
0
 public void AllowLogin_FormatException4()
 {
     string logString = "la=2;";
     Security security = new Security(5, 5);
     security.AllowLogin(logString);
 }
Пример #4
0
 public void AllowLogin_FormatException6()
 {
     string logString = "la=-5;dt=2013-11-11 22:38:00";
     Security security = new Security(5, 5);
     security.AllowLogin(logString);
 }
Пример #5
0
        public ActionResult Login(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {

                var security = new Util.Security(5, 5); // TODO: retrieve settings from DB
                if (security.AllowLogin((string)Session["loginHistory"]))
                {
                    ml_User user = _service.Load(model.userEmail, model.userPassword);
                    if (user != null && user.ID > 0)
                    {
                        FormsAuthentication.SetAuthCookie(user.ID.ToString(), false);
                        FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.ID.ToString(), DateTime.Now, DateTime.Now.AddMinutes(60), false, ((Util.Enum.UserStatus)user.userStatus).ToString());
                        HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket));
                        Response.Cookies.Add(cookie);
                        Session["CurrentUser"] = user;
                        return RedirectToAction("List", "Workout");
                    }
                    else
                    {
                        Session["loginHistory"] = security.AddFailedLoginAttempt((string)Session["loginHistory"]);
                        ModelState.AddModelError("", "Fehlerhafter Benutzername und/oder Passwort.");
                    }
                }
                else
                {
                    ModelState.AddModelError("", Resources.Translations.Home_Anonymous_LoginTimeout);
                }
            }

            return View();
        }