Ejemplo n.º 1
0
        public void SetPassword(string password)
        {
            EncryptionService encrypt = new EncryptionService();

            Salt     = encrypt.CreateSalt();
            Password = encrypt.EncryptPassword(password, Salt);
        }
Ejemplo n.º 2
0
        public void CreateSaltTest()
        {
            IEncryptionService service = new EncryptionService();
            var result = service.CreateSalt();

            Assert.True(!String.IsNullOrWhiteSpace(result));
        }
Ejemplo n.º 3
0
        public ActionResult ResetPassword(FormCollection fc)
        {
            try
            {
                BackLogCrd.LogInId     = Convert.ToInt32(Session["UserId"]);
                BackLogCrd.NewPassword = fc["ConfirmPassword"];
                EncryptionService objES = new EncryptionService();
                BackLogCrd.Salt        = objES.CreateSalt();
                BackLogCrd.NewPassword = objES.EncryptPassword(BackLogCrd.NewPassword, BackLogCrd.Salt);
                int j = objBdata.BackLogLogInUpdate(BackLogCrd);
                if (j >= 1)
                {
                    Session["BackLogResetStatus"]       = 1;
                    TempData["ResetMassageToDashboard"] = 1;
                    TempData["Success"] = "Success";
                    return(RedirectToAction("Dashboard", "BackLog"));
                }
                if (Convert.ToInt32(Session["BackLogResetStatus"]) == 0)
                {
                    ViewBag.result = 1;
                    ViewBag.Err    = "First you set your new password, then you will be go further.";
                    return(RedirectToAction("ResetPassword", "BackLog"));
                }
                return(View());
            }
            catch (Exception ex)
            {
                return(RedirectToAction("LogIn", "Account"));

                throw ex;
            }
        }
Ejemplo n.º 4
0
        public void EncryptPasswordTest()
        {
            IEncryptionService service = new EncryptionService();
            string             salt    = service.CreateSalt();
            var result = service.EncryptPassword("testPassword", salt);

            Assert.True(!String.IsNullOrWhiteSpace(result) && result != "testPassword");
        }
Ejemplo n.º 5
0
        public void EncryptTest()
        {
            EncryptionService encryptionService = new EncryptionService();
            string            salt      = encryptionService.CreateSalt(8);
            string            encrypted = encryptionService.Encrypt("password", salt);
            string            decrypt   = encryptionService.Decrypt(encrypted, salt);

            Assert.AreEqual(decrypt, "password");
        }
Ejemplo n.º 6
0
        public void ValidateUserTest()
        {
            IEncryptionService encryptionService = new EncryptionService();
            string             userSalt          = encryptionService.CreateSalt();
            string             userHash          = encryptionService.EncryptPassword("password", userSalt);

            var ctx = new Mock <IContext>();

            List <Role> roles = new List <Role>
            {
                new Role()
                {
                    Id = 1, Name = "Role1"
                },
                new Role()
                {
                    Id = 2, Name = "Role2"
                }
            };
            List <User> users = new List <User>
            {
                new User()
                {
                    Id = 1, Username = "******", Salt = userSalt, HashedPassword = userHash
                }
            };
            List <UserRole> userRoles = new List <UserRole>
            {
                new UserRole()
                {
                    Id = 1, RoleId = 1, UserId = 1
                },
                new UserRole()
                {
                    Id = 2, RoleId = 2, UserId = 1
                }
            };

            var rolesMockDbSet     = ServiceTestsHelper.GetMockDbSet <Role>(roles);
            var usersMockDbSet     = ServiceTestsHelper.GetMockDbSet <User>(users);
            var userRolesMockDbSet = ServiceTestsHelper.GetMockDbSet <UserRole>(userRoles);

            ctx.Setup(c => c.Set <Role>()).Returns(rolesMockDbSet.Object);
            ctx.Setup(c => c.Set <User>()).Returns(usersMockDbSet.Object);
            ctx.Setup(c => c.Set <UserRole>()).Returns(userRolesMockDbSet.Object);

            IUserService     userService     = new UserService(ctx.Object);
            IRoleService     roleService     = new RoleService(ctx.Object);
            IUserRoleService userRoleService = new UserRoleService(ctx.Object);

            IMembershipService service = new MembershipService(userService, encryptionService, roleService, userRoleService);
            var result = service.ValidateUser("testUser1", "password");

            Assert.NotNull(result.Principal);
        }
Ejemplo n.º 7
0
        public ActionResult CreateInspectorAccount(FormCollection collection)
        {
            InspectorListModel objILM = new InspectorListModel();
            ResgirationModels  objRM  = new ResgirationModels();
            EncryptionService  objES  = new EncryptionService();
            GetDRCSName        objGDN = new GetDRCSName();
            Account            objAcc = new Account();
            var salt = objES.CreateSalt();

            objRM.Username             = collection.Get("UserName");
            objRM.Password             = objES.EncryptPassword(collection.Get("Password"), salt);
            objRM.SecurityQuestionCode = collection.Get("SecurityQuestions");
            objRM.SecurityAnswer       = collection.Get("Anwser");
            objRM.Salt           = salt;
            objGDN.DRCSName      = collection.Get("DRCSName");
            objILM.InspectorName = collection.Get("InspectorOffice");
            objRM.FirstName      = collection.Get("Name");
            if (string.IsNullOrEmpty(objRM.FirstName))
            {
                ModelState.AddModelError("Name", "Please Enter the Name");
            }
            objRM.Mobile       = collection.Get("Mobile");
            objRM.EmailID      = collection.Get("Email");
            objRM.Gender       = collection.Get("Gender");
            objRM.DisCode      = collection.Get("District");
            objRM.ARCSCode     = collection.Get("ARCSOffice");
            objRM.UserTypeCode = 4;
            objRM.Role         = 3;
            objRM.CreatedBy    = "Admin";
            if (ModelState.IsValid)
            {
                int result = objAcc.SaveResgiratedUser(objRM);
                if (result == 1)
                {
                    return(RedirectToAction("Dashboard", "Admin"));
                }
            }
            else
            {
                return(View());
            }
            return(View());
        }
Ejemplo n.º 8
0
        //[ValidateAntiForgeryToken]
        public ActionResult Registration(FormCollection collection)
        {
            try
            {
                ResgirationModels objRM  = new ResgirationModels();
                EncryptionService objES  = new EncryptionService();
                Account           objAcc = new Account();
                var salt = objES.CreateSalt();
                objRM.Username = collection.Get("UserName");
                string pwd = collection.Get("Password");
                objRM.Password             = objES.EncryptPassword(pwd, salt);
                objRM.SecurityQuestionCode = collection.Get("SecurityQuestions");
                objRM.SecurityAnswer       = collection.Get("Anwser");
                objRM.Salt = salt;

                objRM.FirstName = collection.Get("Name");
                if (string.IsNullOrEmpty(objRM.FirstName))
                {
                    ModelState.AddModelError("Name", "Please Enter the Name");
                }
                objRM.Gender     = collection.Get("Gender");
                objRM.Age        = Convert.ToInt32(collection.Get("Age"));
                objRM.Mobile     = collection.Get("Mobile");
                objRM.EmailID    = collection.Get("Email");
                objRM.Address1   = collection.Get("Address");
                objRM.Address2   = collection.Get("HouseNoSectorNoRoad");
                objRM.PostOffice = collection.Get("PostOffice");
                objRM.PostalCode = collection.Get("PostalCode");
                objRM.DisCode    = collection.Get("District");

                objRM.UserTypeCode = 3;
                objRM.Role         = 1;
                objRM.CreatedBy    = "self";

                objRM.FirstName      = Microsoft.Security.Application.Sanitizer.GetSafeHtmlFragment(objRM.FirstName);
                objRM.EmailID        = Microsoft.Security.Application.Sanitizer.GetSafeHtmlFragment(objRM.EmailID);
                objRM.SecurityAnswer = Microsoft.Security.Application.Sanitizer.GetSafeHtmlFragment(objRM.SecurityAnswer);
                objRM.Address1       = Microsoft.Security.Application.Sanitizer.GetSafeHtmlFragment(objRM.Address1);
                objRM.Address2       = Microsoft.Security.Application.Sanitizer.GetSafeHtmlFragment(objRM.Address2);
                objRM.PostOffice     = Microsoft.Security.Application.Sanitizer.GetSafeHtmlFragment(objRM.PostOffice);

                objRM.FirstName      = XCCPrevent.FilterBadchars1(objRM.FirstName);
                objRM.EmailID        = XCCPrevent.FilterBadchars1(objRM.EmailID);
                objRM.SecurityAnswer = XCCPrevent.FilterBadchars1(objRM.SecurityAnswer);
                objRM.Address1       = XCCPrevent.FilterBadchars1(objRM.Address1);
                objRM.Address2       = XCCPrevent.FilterBadchars1(objRM.Address2);
                objRM.PostOffice     = XCCPrevent.FilterBadchars1(objRM.PostOffice);
                if (ModelState.IsValid)
                {
                    int result = objAcc.SaveResgiratedUser(objRM);
                    if (result == 1)
                    {
                        TempData["message"] = "Registered";
                        return(RedirectToAction("Login", "Account"));
                    }
                }
                else
                {
                    return(View());
                }
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Error", "Unauthorised"));

                throw ex;
            }
            return(View());
        }