예제 #1
0
        public void CreateNewInstructor_NewInstructor_NewInstructorCreated()
        {
            //Arrange

            PersonVM modelTest = new PersonVM()
            {
                LastName        = "Green",
                FirstMidName    = "Harry",
                Login           = "******",
                Password        = "******",
                ConfirmPassword = "******",
                Role            = "instructor"
            };

            //Ceci rend le test dependant de la methode GenerateSHA256String(string inputString) de la Classe HashService
            string passwordTest = HashService.GenerateSHA256String(modelTest.Password);

            //Act
            authenticationBusinessToTest.CreateNewInstructor(modelTest);
            Instructor instructor = DBUtils.db.Instructors.SingleOrDefault(s => s.LastName == "Green" && s.FirstMidName == "Harry" && s.Login == "login1" && s.Password == passwordTest);

            //Assert

            Assert.IsNotNull(instructor);
        }
예제 #2
0
        public Person LoginPerson(LoginVM model)
        {
            string EncryptPass = HashService.GenerateSHA256String(model.Password);
            Person user        = db.People.FirstOrDefault(u => u.Login == model.Login && u.Password == EncryptPass);

            return(user);
        }
예제 #3
0
 public ActionResult LoginCheck(LoginViewModel logInfos)
 {
     try
     {
         if (ModelState.IsValid)
         {
             // Move comparaison, and searching of person in an other layer
             PersonBAL balPerson        = new PersonBAL();
             Person    personConnecting = balPerson.GetPersonByLogin(logInfos.Login, db);
             // Move comparaison in an other laver
             if (personConnecting != null && personConnecting.Password == HashService.GenerateSHA256String(logInfos.Password))
             {
                 Session["User"] = personConnecting;
                 ViewBag.User    = Session["User"];
                 return(RedirectToAction(nameof(HomeController.Index), "Home"));
             }
             else
             {
                 Session["User"]        = null;
                 TempData["LoginError"] = "Invalid login or password";
                 return(RedirectToAction(nameof(AccountController.Login), "Account"));
             }
         }
     }
     catch (Exception)
     {
         ModelState.AddModelError("Error", "Error");
     }
     Session["User"]        = null;
     TempData["LoginError"] = "Invalid login or password";
     return(RedirectToAction(nameof(AccountController.Login), "Account"));
 }
예제 #4
0
        public void GenerateSHA256String_ComparePasswordHashToPaswwordNotHash_False()
        {
            string         inputString = "password123";
            string         hash        = HashService.GenerateSHA256String(inputString);
            StringComparer comparer    = StringComparer.OrdinalIgnoreCase;
            int            result      = comparer.Compare(inputString, hash);

            Assert.NotZero(result);
        }
예제 #5
0
        public void GenerateSHA256String_stringToCompare_True()
        {
            string         inputString     = "password123";
            string         hash            = HashService.GenerateSHA256String(inputString);
            string         stringToCompare = HashService.GenerateSHA256String("password123");
            StringComparer comparer        = StringComparer.OrdinalIgnoreCase;
            int            result          = comparer.Compare(stringToCompare, hash);

            Assert.AreEqual(0, result);
        }
예제 #6
0
        public void CreateNewStudent(PersonVM model)
        {
            Student newStudent = new Student
            {
                LastName       = model.LastName,
                FirstMidName   = model.FirstMidName,
                Login          = model.Login,
                Password       = HashService.GenerateSHA256String(model.Password),
                EnrollmentDate = DateTime.Now
            };

            db.Students.Add(newStudent);
            db.SaveChanges();
        }
예제 #7
0
        //CreatePerson for LoginPersonTest
        public Student CreatePersonWithLoginAndPassword(LoginVM model)
        {
            var student = new Student()
            {
                LastName       = "lastname",
                FirstMidName   = "firstname",
                Login          = model.Login,
                Password       = HashService.GenerateSHA256String(model.Password),
                EnrollmentDate = DateTime.Now
            };

            DBUtils.db.Students.Add(student);
            DBUtils.db.SaveChanges();
            return(student);
        }
예제 #8
0
        public void CreateNewInstructor(PersonVM model)
        {
            Instructor newInstructor = new Instructor
            {
                LastName     = model.LastName,
                FirstMidName = model.FirstMidName,
                Login        = model.Login,
                Password     = HashService.GenerateSHA256String(model.Password),
                HireDate     = DateTime.Now
            };

            db.Instructors.Add(newInstructor);


            db.SaveChanges();
        }
예제 #9
0
 public void CreateInstructorRegistering(PersonRegisterViewModel newAccount, SchoolContext db)
 {
     try
     {
         using (this.db)
         {
             Instructor newInstructor = new Instructor();
             newInstructor.LastName     = newAccount.LastName;
             newInstructor.FirstMidName = newAccount.FirstMidName;
             newInstructor.Login        = newAccount.Login;
             newInstructor.Password     = HashService.GenerateSHA256String(newAccount.Password);
             newInstructor.HireDate     = DateTime.Now;
             db.Instructors.Add(newInstructor);
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
예제 #10
0
 public void CreateStudentRegistering(PersonRegisterViewModel newAccount, SchoolContext db)
 {
     try
     {
         using (this.db)
         {
             Student newStudent = new Student();
             newStudent.LastName       = newAccount.LastName;
             newStudent.FirstMidName   = newAccount.FirstMidName;
             newStudent.Login          = newAccount.Login;
             newStudent.Password       = HashService.GenerateSHA256String(newAccount.Password);
             newStudent.EnrollmentDate = DateTime.Now;
             db.Students.Add(newStudent);
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }