Esempio n. 1
0
        public ActionResult Register(RegisterUser model)
        {
            if (model.Password != model.ConfirmedPassword && !String.IsNullOrEmpty(model.Password))
            {
                ModelState.AddModelError("UnconfirmedPassword", "Please Confirm Your Password.");
            }
            if (!ModelState.IsValid)
            {
                return(View("Register", model));
            }

            if (userDAL.GetUser(model).EmailAddress != model.EmailAddress)
            {
                HashProvider hashProvider   = new HashProvider();
                string       hashedPassword = hashProvider.HashPassword(model.Password); //<-- password they provided during registration
                string       salt           = hashProvider.SaltValue;
                model.Salt     = salt;
                model.Password = hashedPassword;
                userDAL.InsertNewUser(model);
                User validatedUser = userDAL.GetUser(model);
                Session["Login"] = validatedUser;

                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                return(View());
            }
        }
        public ActionResult <dynamic> EmployeeRegister(NewUserModel model)
        {
            // Validate Request
            if (String.IsNullOrEmpty(model.Username) || String.IsNullOrEmpty(model.Password))
            {
                return(BadRequest(new { Message = "Username or password missing." }));
            }
            if (userDAL.GetUser(model.Username) != null)
            {
                return(BadRequest(new { Message = "User already exists" }));
            }

            // Create the user
            var hashProvider   = new HashProvider();
            var hashedPassword = hashProvider.HashPassword(model.Password);
            var user           = new User
            {
                Password = hashedPassword.Password,
                Salt     = hashedPassword.Salt,
                Username = model.Username,
                Role     = "employee"
            };

            userDAL.CreateUser(user);

            return(Ok());
        }
Esempio n. 3
0
        public ActionResult Password(string password)
        {
            HashProvider   hashProvider   = new HashProvider();
            HashedPassword hashedPassword = hashProvider.HashPassword(password);

            return(Ok(hashedPassword));
        }
Esempio n. 4
0
        public ActionResult NewUser(NewUserViewModel model)
        {
            if (IsAuthenticated)
            {
                return(RedirectToAction("Index", "Home"));
            }
            if (ModelState.IsValid)
            {
                var currentUser = usersDAL.GetUser(model.Username);
                if (currentUser != null)
                {
                    ModelState.AddModelError("Username", "This username is unavailable.");
                    return(View("newUser", model));
                }
                var hashProvider   = new HashProvider();
                var hashedPassword = hashProvider.HashPassword(model.Password);
                var salt           = hashProvider.SaltValue;

                var newUser = new UserModel
                {
                    Username = model.Username,
                    Password = hashedPassword,
                    Salt     = salt
                };

                usersDAL.RegisterNewUser(newUser);

                LogUserIn(model.Username);
                return(RedirectToAction("Index", "Home"));
            }
            return(View("NewUser", model));
        }
Esempio n. 5
0
        public ActionResult Register(UserModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Register"));
            }


            UserModel user = userDal.GetUser(model.UserName);

            if (user.UserName != null)
            {
                ModelState.AddModelError("username-exists", "That user name is not available");
                return(View("Register", model));
            }
            else
            {
                HashProvider hash     = new HashProvider();
                string       password = hash.HashPassword(model.Password);
                model.Salt               = hash.SaltValue;
                model.Password           = password;
                model.AuthorizationLevel = 2;
                if (model.SignupBool == true)
                {
                    model.Signup = 1;
                }
                userDal.RegisterUser(model);

                FormsAuthentication.SetAuthCookie(user.Email, true);
                // Session[SessionKeys.Username] = model.EmailAddress;
                //Session[SessionKeys.UserId] = user.Id;  ??? whats session keys
            }

            return(RedirectToAction("RegisterSuccess"));
        }
Esempio n. 6
0
        public void HashProvider_ReturnsHashedPassword()
        {
            HashProvider hashProvider = new HashProvider();

            var hashedPassword = hashProvider.HashPassword("password123");

            Assert.IsNotNull(hashedPassword.Salt);
            Assert.AreNotEqual(hashedPassword.Password, "password123");
        }
Esempio n. 7
0
        public IActionResult CreateUserForm(User user)
        {
            HashProvider   hashProvider = new HashProvider();
            HashedPassword newPasscode  = hashProvider.HashPassword(user.Password);

            user.Salt     = newPasscode.Salt;
            user.Password = newPasscode.Password;

            userDAL.CreateUser(user);

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 8
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            UserModel    user = Session["user"] as UserModel;
            HashProvider hash = new HashProvider();
            string       s    = model.TempPassword;

            s = hash.HashPassword(s);


            //if (!ModelState.IsValid)
            //{
            //    return View("ChangePassword");
            //}



            if (hash.VerifyPasswordMatch(user.Password, model.TempPassword, user.Salt) == false)
            {
                return(View("ChangePassword"));
            }

            else
            {
                string password = hash.HashPassword(model.Password);
                user.Salt               = hash.SaltValue;
                model.Password          = password;
                user.AuthorizationLevel = 2;
                userDal.ChangePassword(model.Password, user.Salt, user.UserName);

                //FormsAuthentication.SetAuthCookie(user.Email, true);
                // Session[SessionKeys.Username] = model.EmailAddress;
                //Session[SessionKeys.UserId] = user.Id;  ??? whats session keys
            }

            return(RedirectToAction("ChangeSuccess"));
        }
Esempio n. 9
0
        public ActionResult ChangePassword(ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("ChangePassword", model));
            }

            string       username       = base.CurrentUser;
            HashProvider hashProvider   = new HashProvider();
            string       hashedPassword = hashProvider.HashPassword(model.NewPassword);

            userDAL.ChangePassword(username, hashedPassword);

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 10
0
        public IActionResult ChangePass(User editedUser)
        {
            User newUser        = userDAL.GetUserWithDapper(editedUser.Username);
            var  hashProvider   = new HashProvider();
            var  hashedPassword = hashProvider.HashPassword(editedUser.Password);
            var  user           = new User
            {
                Password = hashedPassword.Password,
                Salt     = hashedPassword.Salt,
                Username = newUser.Username,
                Role     = newUser.Role,
                GoalType = newUser.GoalType,
                GoalReps = newUser.GoalReps,
                Id       = newUser.Id
            };

            userDAL.UpdateUser(user);
            return(RedirectToAction("UserList", "Account"));
        }
Esempio n. 11
0
        public IActionResult ResetUser(User user)
        {
            User loggedIn = authProvider.GetCurrentUser();

            if (loggedIn == null)
            {
                return(RedirectToAction("Error", "Account"));
            }

            HashProvider hashProvider = new HashProvider();

            HashedPassword newPasscode = hashProvider.HashPassword(user.Password);

            user.Salt     = newPasscode.Salt;
            user.Password = newPasscode.Password;
            userDAL.UpdateUser(user);

            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 12
0
        public ActionResult CreateProfile(UserProfile userProfile)
        {
            var checkExists = userSqlDAL.GetUser(userProfile.UserEmail);

            if (checkExists != null)
            {
                return(View("CreateProfileUserNameTaken"));
            }

            var hashedPasswordAndSalt = hashProvider.HashPassword(userProfile.UserPassword);

            userProfile.UserPassword = hashedPasswordAndSalt.Password;
            userProfile.Salt         = hashedPasswordAndSalt.Salt;
            userSqlDAL.CreateUser(userProfile);
            SaveUserSession(userProfile.UserEmail);


            return(RedirectToAction("Survey", "Home")); //Jarrod: changed this to redirect to the survey, before it was going to profile and crashing because they hadnt made a profile yet
        }
        public ActionResult NewUser(NewUserViewModel model)
        {
            if (base.IsAuthenticated)
            {
                return(RedirectToAction("Dashboard", "Messages", new { username = base.CurrentUser }));
            }

            if (ModelState.IsValid)
            {
                var currentUser = userDal.GetUser(model.Username);

                if (currentUser != null)
                {
                    ViewBag.ErrorMessage = "This username is unavailable";
                    return(View("NewUser", model));
                }


                HashProvider hashProvider   = new HashProvider();
                string       hashedPassword = hashProvider.HashPassword(model.Password); //<-- password they provided during registration
                string       salt           = hashProvider.SaltValue;


                var newUser = new User
                {
                    Username = model.Username,
                    Password = hashedPassword,
                    //Salt = salt
                };

                // Add the user to the database
                userDal.CreateUser(newUser);

                // Log the user in and redirect to the dashboard
                base.LogUserIn(model.Username);
                return(RedirectToAction("Dashboard", "Messages", new { username = model.Username }));
            }
            else
            {
                return(View("NewUser", model));
            }
        }
        public ActionResult Registration(ChildRegistrationModel viewModel)
        {
            // check if logged in
            if (Session["parent"] == null)
            {
                return(RedirectToAction("Login", "Parent"));
            }

            // validation redirect
            if (!ModelState.IsValid)
            {
                return(View("Registration", viewModel));
            }

            ChildModel child = childDAL.GetChild(viewModel.User_Name);

            // check for duplicate username
            if (child != null)
            {
                ModelState.AddModelError("user name-exists", "That user name is already registered.");
                return(View("Registration", viewModel));
            }
            else
            {
                child = new ChildModel
                {
                    First_Name = viewModel.First_Name,
                    UserName   = viewModel.User_Name,
                };

                HashProvider hash = new HashProvider();
                child.Password = hash.HashPassword(viewModel.Password);
                child.Salt     = hash.SaltValue;

                ParentModel parent = Session["parent"] as ParentModel;
                child.Parent_Id = parent.Parent_ID;

                childDAL.CreateChild(child);
            }
            return(RedirectToAction("Dashboard", "Parent"));
        }
Esempio n. 15
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Register", model));
            }

            var currentUser = userDAL.GetUser(model.Username);

            // If username already exists, return to page
            if (currentUser != null)
            {
                ViewBag.ErrorMessage = "This username is unavailable";
                return(View("Register", model));
            }

            // Otherwise, give user new salt value
            HashProvider hashProvider   = new HashProvider();
            string       hashedPassword = hashProvider.HashPassword(model.Password);
            string       salt           = hashProvider.SaltValue;

            // Assign properties to user
            var newUser = new User
            {
                FirstName = model.FirstName,
                LastName  = model.LastName,
                Email     = model.EmailAddress,
                Username  = model.Username,
                Password  = hashedPassword,
                Salt      = salt
            };

            // Add the user to the database
            userDAL.RegisterUser(newUser);

            // Log the user in and redirect to the home screen
            base.LogUserIn(model.Username);
            return(RedirectToAction("Index", "Home"));
        }
Esempio n. 16
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Register", model));
            }

            User user = userDal.GetUser(model.EmailAddress);

            // Check to see if the username already exists
            if (user != null)
            {
                ModelState.AddModelError("username-exists", "That email address is not available");
                return(View("Register", model));
            }
            else
            {
                HashProvider hashProvider   = new HashProvider();
                string       hashedPassword = hashProvider.HashPassword(model.Password);
                string       salt           = hashProvider.SaltValue; //<-- the user doesn't have  a salt value in the DAL
                // Convert from the ViewModel to a Data Model and Save
                user = new User()
                {
                    Username = model.Username,
                    Email    = model.EmailAddress,
                    Password = hashedPassword,
                    Salt     = salt
                };
                userDal.SaveUser(user);

                FormsAuthentication.SetAuthCookie(user.Email, true);
                Session[SessionKeys.Username]     = model.Username;
                Session[SessionKeys.EmailAddress] = model.EmailAddress;
                Session[SessionKeys.UserId]       = user.User_Id;
            }

            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult Registration(ParentRegistrationModel viewModel)
        {
            // validation redirect
            if (!ModelState.IsValid)
            {
                return(View("Registration", viewModel));
            }

            ParentModel newParent = parentDAL.GetParent(viewModel.Email);

            // check for duplicate email
            if (newParent != null)
            {
                ModelState.AddModelError("email-exists", "That email address is already registered.");
                return(View("Registration", viewModel));
            }
            else
            {
                newParent = new ParentModel
                {
                    First_Name = viewModel.First_Name,
                    Last_Name  = viewModel.Last_Name,
                    Email      = viewModel.Email,
                };

                HashProvider hash = new HashProvider();
                newParent.Password = hash.HashPassword(viewModel.Password);
                newParent.Salt     = hash.SaltValue;

                parentDAL.CreateParent(newParent);
            }

            // get saved parent model
            ParentModel parent = parentDAL.GetParent(newParent.Email);

            Session["parent"] = parent;
            return(RedirectToAction("Dashboard"));
        }
Esempio n. 18
0
        public ActionResult Register(UserModel user)
        {
            UserSqlDal dal = new UserSqlDal();

            if (ModelState.IsValid)
            {
                var newUser = new UserModel
                {
                    Username = user.Username,
                    Password = user.Password,
                };

                List <string> existingUsers = dal.GetAllUsernames();
                foreach (string name in existingUsers)
                {
                    if (name == user.Username)
                    {
                        user.IsTaken = true;
                        return(View("Register", user));
                    }
                }

                var hashProvider = new HashProvider();
                user.Password = hashProvider.HashPassword(user.Password);
                user.Salt     = hashProvider.SaltValue;

                dal.Register(user);
                Session["user"]     = user;
                Session["username"] = user.Username;
                user.IsTaken        = false;

                return(RedirectToAction("LoggedInLanding", "Home"));
            }
            else
            {
                return(View("Register", user));
            }
        }