Exemplo n.º 1
0
        // GET: PasswordReset
        public ActionResult Reset(ResetPasswordModel resetPasswordModel)
        {
            if (ModelState.IsValid)
            {
                var userId = Convert.ToInt64(Session["VerificationUserId"]);

                if (!string.Equals(resetPasswordModel.Password, resetPasswordModel.ConfirmPassword, StringComparison.Ordinal))
                {
                    TempData["Reset_Error_Message"] = "Password Does not Match";
                    return(View(resetPasswordModel));
                }
                else
                {
                    var salt           = GenerateRandomNumbers.RandomNumbers(20);
                    var saltedpassword = GenerateHashSha512.Sha512(resetPasswordModel.Password, salt);
                    var result         = _iPassword.UpdatePasswordandHistory(userId, saltedpassword, salt, "R");

                    if (result)
                    {
                        var updateresult = _verification.UpdateResetVerification(userId);
                        Session["VerificationUserId"] = null;
                        return(RedirectToAction("Login", "Login"));
                    }
                    else
                    {
                        TempData["Reset_Error_Message"] = "Something Went Wrong Please try again!";
                        return(View(resetPasswordModel));
                    }
                }
            }

            return(View(resetPasswordModel));
        }
        public IActionResult Reset(ResetPasswordViewModel resetPasswordViewModel)
        {
            if (ModelState.IsValid)
            {
                var userid         = Convert.ToString(HttpContext.Session.GetString("VerificationUserId"));
                var getuserdetails = _userRepository.GetUserbyUserId(Convert.ToInt64(userid));

                if (!string.Equals(resetPasswordViewModel.Password, resetPasswordViewModel.ConfirmPassword, StringComparison.Ordinal))
                {
                    TempData["Reset_Error_Message"] = "Password Does not Match";
                    return(View(resetPasswordViewModel));
                }
                else
                {
                    var salt           = GenerateRandomNumbers.RandomNumbers(20);
                    var saltedpassword = GenerateHashSha512.Sha512(resetPasswordViewModel.Password, salt);
                    var result         = _userRepository.UpdatePasswordandHistory(getuserdetails.UserId, saltedpassword, salt, "R");

                    if (result > 0)
                    {
                        var updateresult = _verificationRepository.UpdateResetVerification(getuserdetails.UserId);
                        return(RedirectToAction("Login", "Portal"));
                    }
                    else
                    {
                        TempData["Reset_Error_Message"] = "Something Went Wrong Please try again!";
                        return(View(resetPasswordViewModel));
                    }
                }
            }

            return(View(resetPasswordViewModel));
        }
        public IActionResult Register(RegisterViewModel registerViewModel)
        {
            if (ModelState.IsValid)
            {
                if (_userRepository.CheckUserExists(registerViewModel.UserName))
                {
                    ModelState.AddModelError("", "Entered Username Already Exists");
                    return(View(registerViewModel));
                }

                if (_userRepository.CheckUserExists(registerViewModel.Email))
                {
                    ModelState.AddModelError("", "Entered EmailId Already Exists");
                    return(View(registerViewModel));
                }

                if (_userRepository.CheckUserExists(registerViewModel.Phoneno))
                {
                    ModelState.AddModelError("", "Entered Phoneno Already Exists");
                    return(View(registerViewModel));
                }

                if (!string.Equals(registerViewModel.Password, registerViewModel.ConfirmPassword,
                                   StringComparison.Ordinal))
                {
                    TempData["Registered_Error_Message"] = "Password Does not Match";
                    return(View(registerViewModel));
                }

                var salt           = GenerateRandomNumbers.RandomNumbers(20);
                var saltedpassword = GenerateHashSha512.Sha512(registerViewModel.Password, salt);

                User user = new User()
                {
                    FullName     = registerViewModel.FullName,
                    CreatedDate  = DateTime.Now,
                    PasswordHash = saltedpassword,
                    Status       = true,
                    UserId       = 0,
                    Username     = registerViewModel.UserName,
                    Email        = registerViewModel.Email,
                    Phoneno      = registerViewModel.Phoneno
                };

                var userId = _userRepository.RegisterUser(user, salt);
                if (userId > 0)
                {
                    Send(userId, registerViewModel);
                    TempData["Registered_Success_Message"] = "User Registered Successfully";
                }
                else
                {
                    TempData["Registered_Error_Message"] = "Error While Registrating User Successfully";
                }
            }

            return(RedirectToAction("Register", "Registration"));
        }
Exemplo n.º 4
0
        public ActionResult Create(CreateUserViewModel createUserViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (_iUserMaster.CheckEmailIdExists(createUserViewModel.EmailId))
                    {
                        TempData["MessageCreateUsersErrors"] = "EmailId Already Exists";
                    }
                    else if (_iUserMaster.CheckMobileNoExists(createUserViewModel.MobileNo))
                    {
                        TempData["MessageCreateUsersErrors"] = "MobileNo Already Exists";
                    }
                    else if (_iUserMaster.CheckUsernameExists(createUserViewModel.UserName))
                    {
                        ModelState.AddModelError("", "Username already exists");
                    }
                    else
                    {
                        createUserViewModel.FirstName = UppercaseFirst(createUserViewModel.FirstName);
                        createUserViewModel.LastName  = UppercaseFirst(createUserViewModel.LastName);
                        var usermaster = AutoMapper.Mapper.Map <Usermaster>(createUserViewModel);
                        usermaster.Status     = true;
                        usermaster.CreateDate = DateTime.Now;
                        usermaster.UserId     = 0;
                        usermaster.CreatedBy  = Convert.ToInt32(_sessionHandler.UserId);
                        var salt           = GenerateRandomNumbers.RandomNumbers(20);
                        var saltedpassword = GenerateHashSha512.Sha512(createUserViewModel.Password, salt);

                        var userId = _iUserMaster.AddUser(usermaster, saltedpassword, salt, createUserViewModel.RoleId);
                        if (userId != -1)
                        {
                            TempData["MessageCreateUsers"] = "User Created Successfully";
                        }

                        return(RedirectToAction("Create", "CreateUsers"));
                    }

                    createUserViewModel.ListRole = _iRole.GetAllActiveRolesNotAgent();
                    return(View("Create", createUserViewModel));
                }
                else
                {
                    createUserViewModel.ListRole = _iRole.GetAllActiveRolesNotAgent();
                    return(View("Create", createUserViewModel));
                }
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 5
0
        public ActionResult ChangePassword(ChangePasswordFirstLoginModel changePassword)
        {
            if (ModelState.IsValid)
            {
                var storedUserpassword = _password.GetPasswordbyUserId(Convert.ToInt64(Session["ChangePasswordUserId"]));
                var usersalt           = _userMaster.GetUserSaltbyUserid(Convert.ToInt64(Session["ChangePasswordUserId"]));
                var userrole           = Session["ChangeRoleId"];
                var generatehash       = GenerateHashSha512.Sha512(changePassword.CurrentPassword, usersalt.PasswordSalt);
                var rolesModel         = _savedAssignedRoles.GetAssignedRolesbyUserId(Convert.ToInt64(Session["ChangePasswordUserId"]));


                if (changePassword.CurrentPassword == changePassword.NewPassword)
                {
                    ModelState.AddModelError("", @"New Password Cannot be same as Old Password");
                    return(View(changePassword));
                }

                if (!string.Equals(storedUserpassword, generatehash, StringComparison.Ordinal))
                {
                    ModelState.AddModelError("", "Current Password Entered is InValid");
                    return(View(changePassword));
                }

                if (!string.Equals(changePassword.NewPassword, changePassword.ConfirmPassword, StringComparison.Ordinal))
                {
                    TempData["ChangePasswordErrorMessage"] = "Something Went Wrong Please Try Again!";
                    return(View(changePassword));
                }
                else
                {
                    var userid             = Convert.ToInt64(Session["ChangePasswordUserId"]);
                    var usermasterModel    = _userMaster.GetUserById(userid);
                    var salt               = GenerateRandomNumbers.RandomNumbers(20);
                    var saltedpassword     = GenerateHashSha512.Sha512(changePassword.NewPassword, salt);
                    var result             = _password.UpdatePasswordandHistory(userid, saltedpassword, salt, "C");
                    var resultIsFirstLogin = _userMaster.UpdateIsFirstLogin(userid);
                    if (result && resultIsFirstLogin > 0)
                    {
                        TempData["ChangePasswordMessage"] = "Password Changed Successfully You might need to sign in again";
                        AssignSessionValues(usermasterModel, rolesModel);
                        return(RedirectionManager(usermasterModel, rolesModel));
                    }
                    else
                    {
                        TempData["ChangePasswordErrorMessage"] = "Something Went Wrong Please Try Again!";
                        return(View(changePassword));
                    }
                }
            }

            return(View(changePassword));
        }
Exemplo n.º 6
0
        public IActionResult Login(LoginViewModel loginViewModel)
        {
            if (ModelState.IsValid)
            {
                if (!_userRepository.CheckUserExists(loginViewModel.UserName))
                {
                    ModelState.AddModelError("", "Entered Username or Password is Invalid");
                }
                else
                {
                    var getuserdetails = _userRepository.GetUserbyUserName(loginViewModel.UserName);

                    if (getuserdetails == null)
                    {
                        ModelState.AddModelError("", "Entered Username or Password is Invalid");
                        return(View());
                    }

                    var usersalt = _userRepository.GetUserSaltbyUserid(getuserdetails.UserId);
                    if (usersalt == null)
                    {
                        ModelState.AddModelError("", "Entered Username or Password is Invalid");
                        return(View());
                    }

                    if (!_verificationRepository.CheckIsAlreadyVerifiedRegistration(getuserdetails.UserId))
                    {
                        ModelState.AddModelError("", "Email Verification Pending");
                        return(View());
                    }

                    var generatehash = GenerateHashSha512.Sha512(loginViewModel.Password, usersalt.PasswordSalt);

                    if (string.Equals(getuserdetails.PasswordHash, generatehash, StringComparison.Ordinal))
                    {
                        HttpContext.Session.SetString("UserId", Convert.ToString(getuserdetails.UserId));
                        HttpContext.Session.SetString("UserName", Convert.ToString(getuserdetails.Username));

                        return(RedirectToAction("Dashboard", "Dashboard"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Entered Username or Password is Invalid");
                    }

                    return(View());
                }
            }

            return(View());
        }
        public IActionResult Process(ChangePasswordViewModel changePasswordViewModel)
        {
            if (ModelState.IsValid)
            {
                var userid         = Convert.ToString(HttpContext.Session.GetString("UserId"));
                var getuserdetails = _userRepository.GetUserbyUserId(Convert.ToInt64(userid));
                var usersalt       = _userRepository.GetUserSaltbyUserid(getuserdetails.UserId);
                var generatehash   = GenerateHashSha512.Sha512(changePasswordViewModel.CurrentPassword, usersalt.PasswordSalt);

                if (changePasswordViewModel.CurrentPassword == changePasswordViewModel.Password)
                {
                    ModelState.AddModelError("", @"New Password Cannot be same as Old Password");
                    return(View(changePasswordViewModel));
                }

                if (!string.Equals(getuserdetails.PasswordHash, generatehash, StringComparison.Ordinal))
                {
                    ModelState.AddModelError("", "Current Password Entered is InValid");
                    return(View(changePasswordViewModel));
                }

                if (!string.Equals(changePasswordViewModel.Password, changePasswordViewModel.ConfirmPassword, StringComparison.Ordinal))
                {
                    TempData["Reset_Error_Message"] = "Password Does not Match";
                    return(View(changePasswordViewModel));
                }
                else
                {
                    var salt           = GenerateRandomNumbers.RandomNumbers(20);
                    var saltedpassword = GenerateHashSha512.Sha512(changePasswordViewModel.Password, salt);
                    var result         = _userRepository.UpdatePasswordandHistory(getuserdetails.UserId, saltedpassword, salt, "C");

                    if (result > 0)
                    {
                        //
                        TempData["ChangePassword_Success_Message"] = "Password Changed Successfully";
                        var updateresult = _verificationRepository.UpdateRegisterVerification(getuserdetails.UserId);
                        return(RedirectToAction("Process", "ChangePassword"));
                    }
                    else
                    {
                        TempData["Reset_Error_Message"] = "Something Went Wrong Please try again!";
                        return(View(changePasswordViewModel));
                    }
                }
            }

            return(View(changePasswordViewModel));
        }
Exemplo n.º 8
0
 //tkts + onecharfirstName + onecharlastName + mobileno5 digit
 private string GeneratePassword(CreateNewUserViewModel createUserViewModel, string salt)
 {
     try
     {
         string onecharfirstName = createUserViewModel.FirstName.Substring(0, 1);
         string onecharlastName  = createUserViewModel.LastName.Substring(0, 1);
         string mobileno         = createUserViewModel.MobileNo.Substring(5, 5);
         string password         = string.Concat("tkts", onecharfirstName.ToLower(), onecharlastName.ToLower(), mobileno);
         var    saltedpassword   = GenerateHashSha512.Sha512(password, salt);
         return(saltedpassword);
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 9
0
        public ActionResult Changepassword(ChangePasswordViewModel changePasswordViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var storedUserpassword = _password.GetPasswordbyUserId(Convert.ToInt64(_sessionHandler.UserId));
                    var usersalt           = _userMaster.GetUserSaltbyUserid(Convert.ToInt64(_sessionHandler.UserId));
                    var generatehash       = GenerateHashSha512.Sha512(changePasswordViewModel.ExistingPassword, usersalt.PasswordSalt);

                    if (changePasswordViewModel.ExistingPassword == changePasswordViewModel.NewPassword)
                    {
                        ModelState.AddModelError("", @"New Password Cannot be same as Old Password");
                        return(View(changePasswordViewModel));
                    }

                    if (!string.Equals(storedUserpassword, generatehash, StringComparison.Ordinal))
                    {
                        ModelState.AddModelError("", "Current Password Entered is InValid");
                        return(View(changePasswordViewModel));
                    }

                    if (!string.Equals(changePasswordViewModel.NewPassword, changePasswordViewModel.ConfirmPassword, StringComparison.Ordinal))
                    {
                        TempData["Reset_Error_Message"] = "Password Does not Match";
                        return(View(changePasswordViewModel));
                    }
                    else
                    {
                        var salt           = GenerateRandomNumbers.RandomNumbers(20);
                        var saltedpassword = GenerateHashSha512.Sha512(changePasswordViewModel.NewPassword, salt);
                        var result         = _password.UpdatePasswordandHistory(Convert.ToInt64(_sessionHandler.UserId), saltedpassword, salt, "C");
                        TempData["MessageChangePassword"] = "******";
                        return(RedirectToAction("Changepassword", "Admin"));
                    }
                }
                return(View(changePasswordViewModel));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 10
0
        public async Task <ActionResult> Register(UsermasterView usermaster)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!this.IsCaptchaValid("Captcha is not valid"))
                    {
                        ModelState.AddModelError("", "Error: captcha is not valid.");
                        return(View(usermaster));
                    }

                    if (_iUserMaster.CheckUsernameExists(usermaster.UserName))
                    {
                        ModelState.AddModelError("", "UserName already exists");
                        return(View(usermaster));
                    }

                    if (_iUserMaster.CheckEmailIdExists(usermaster.EmailId))
                    {
                        ModelState.AddModelError("", "EmailId already exists");
                        return(View(usermaster));
                    }

                    if (_iUserMaster.CheckMobileNoExists(usermaster.MobileNo))
                    {
                        TempData["MessageCreateUsersErrors"] = "MobileNo Already Exists";
                    }

                    var autoUsermaster = AutoMapper.Mapper.Map <Usermaster>(usermaster);
                    var salt           = GenerateRandomNumbers.RandomNumbers(20);
                    var saltedpassword = GenerateHashSha512.Sha512(usermaster.Password, salt);

                    var userId = _iUserMaster.AddUser(autoUsermaster, saltedpassword, salt, Convert.ToInt16(StatusMain.Roles.User));
                    if (userId != -1)
                    {
                        var emailVerficationToken = GenerateHashSha256.ComputeSha256Hash((GenerateRandomNumbers.RandomNumbers(6)));
                        _verification.SendRegistrationVerificationToken(userId, emailVerficationToken);

                        SendingEmailhelper sendingEmailhelper = new SendingEmailhelper();
                        var name = string.Concat(usermaster.FirstName, usermaster.LastName);
                        await sendingEmailhelper.SendVerificationEmailasync(usermaster.EmailId, name, emailVerficationToken, "Registration", Convert.ToString(userId));

                        TempData["MessageRegistration"] = "Thank you. Your Registration has been completed successfully.";
                    }
                    else
                    {
                        TempData["ErrorRegistration"] = "Something Went Wrong While you are registering.Please try after sometime.";
                    }

                    return(RedirectToAction("Register", "Registration"));
                }
                else
                {
                    return(View("Register", usermaster));
                }
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 11
0
        public ActionResult Create(CreateAgentViewModel createAgentViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var isUser = _iUserMaster.CheckUsernameExists(createAgentViewModel.UserName);

                    if (createAgentViewModel.CategoryId == null)
                    {
                        ModelState.AddModelError("", "Select Category");
                    }
                    else if (isUser)
                    {
                        ModelState.AddModelError("", "Username already exists");
                    }
                    else
                    {
                        var usermaster = AutoMapper.Mapper.Map <Usermaster>(createAgentViewModel);
                        usermaster.Status       = true;
                        usermaster.CreateDate   = DateTime.Now;
                        usermaster.UserId       = 0;
                        usermaster.CreatedBy    = Convert.ToInt32(_sessionHandler.UserId);
                        usermaster.IsFirstLogin = true;

                        var salt           = GenerateRandomNumbers.RandomNumbers(20);
                        var saltedpassword = GenerateHashSha512.Sha512(createAgentViewModel.Password, salt);

                        var savedAssignedRoles = new SavedAssignedRoles()
                        {
                            RoleId         = Convert.ToInt16(StatusMain.Roles.Agent),
                            AssignedRoleId = 0,
                            Status         = true,
                            CreateDate     = DateTime.Now
                        };

                        var result = _iUserMaster.AddAgent(usermaster, saltedpassword, savedAssignedRoles, createAgentViewModel.CategoryId, salt);

                        if (result > 0)
                        {
                            TempData["MessageCreateUsers"] = "Agent Created Successfully";
                            return(RedirectToAction("Create", "CreateAgent"));
                        }
                        else
                        {
                            return(View(createAgentViewModel));
                        }
                    }

                    createAgentViewModel.ListofCategory = _category.GetAllActiveSelectListItemCategory();
                    return(View("Create", createAgentViewModel));
                }
                else
                {
                    createAgentViewModel.ListofCategory = _category.GetAllActiveSelectListItemCategory();
                    return(View("Create", createAgentViewModel));
                }
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 12
0
        public ActionResult Login(LoginViewModel loginViewModel)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!_iUserMaster.CheckUsernameExists(loginViewModel.Username))
                    {
                        TempData["LoginErrors"] = "Invalid Credentials";
                        return(View(loginViewModel));
                    }

                    var usermasterModel = _iUserMaster.GetUserByUsername(loginViewModel.Username);
                    if (usermasterModel != null)
                    {
                        if (usermasterModel.Status == false)
                        {
                            TempData["LoginErrors"] = "User Account is Deactivated Please Contact Admin";
                            return(View(loginViewModel));
                        }

                        var usersalt = _iUserMaster.GetUserSaltbyUserid(Convert.ToInt64(usermasterModel.UserId));
                        if (usersalt == null)
                        {
                            TempData["LoginErrors"] = "Entered Username or Password is Invalid";
                            return(View());
                        }

                        var storedpassword = _password.GetPasswordbyUserId(usermasterModel.UserId);
                        if (storedpassword == null)
                        {
                            TempData["LoginErrors"] = "Invalid Credentials";
                            return(View(loginViewModel));
                        }

                        var generatehash = GenerateHashSha512.Sha512(loginViewModel.Password, usersalt.PasswordSalt);


                        if (string.Equals(storedpassword, generatehash, StringComparison.Ordinal))
                        {
                            if (_savedAssignedRoles.GetAssignedRolesbyUserId(usermasterModel.UserId) != null)
                            {
                                var rolesModel = _savedAssignedRoles.GetAssignedRolesbyUserId(usermasterModel.UserId);

                                if (rolesModel.RoleId == Convert.ToInt32(StatusMain.Roles.User))
                                {
                                    if (!_verification.CheckIsEmailVerifiedRegistration(usermasterModel.UserId))
                                    {
                                        TempData["LoginErrors"] = "Please Verify Your Email-Id to Use Application";
                                        return(View(loginViewModel));
                                    }

                                    ApplicationCustomSettings applicationCustomSettings = new ApplicationCustomSettings();
                                    if (applicationCustomSettings.GetGeneralSetting().EnableEmailFeature&& _verify.CheckVerificationCodeExists(usermasterModel.UserId))
                                    {
                                        TempData["LoginErrors"] = "Please Verify Your Email-Id to Use Application";
                                        return(View(loginViewModel));
                                    }
                                }


                                if (rolesModel.RoleId == Convert.ToInt32(StatusMain.Roles.Agent) || rolesModel.RoleId == Convert.ToInt32(StatusMain.Roles.AgentAdmin) || rolesModel.RoleId == Convert.ToInt32(StatusMain.Roles.Hod))
                                {
                                    if (!IsCategogryAssigned(usermasterModel, rolesModel))
                                    {
                                        TempData["LoginErrors"] = "Category is not Assigned, Please contact your administrator";
                                        return(View(loginViewModel));
                                    }
                                }

                                if (usermasterModel.IsFirstLogin)
                                {
                                    Session["ChangePasswordUserId"] = usermasterModel.UserId;
                                    Session["ChangeRoleId"]         = rolesModel.RoleId;
                                    return(RedirectToAction("ChangePassword", "Force"));
                                }

                                AssignSessionValues(usermasterModel, rolesModel);
                                return(RedirectionManager(usermasterModel, rolesModel));
                            }
                            else
                            {
                                TempData["LoginErrors"] = "Access Not Assigned";
                                return(View(loginViewModel));
                            }
                        }
                        else
                        {
                            TempData["LoginErrors"] = "Invalid Credentials";
                            return(View(loginViewModel));
                        }
                    }
                    else
                    {
                        TempData["LoginErrors"] = "Invalid Credentials";
                        return(View(loginViewModel));
                    }
                }
                else
                {
                    return(View(loginViewModel));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
 private void CheckIsPasswordAlreadyExists(ResetPasswordViewModel resetPasswordViewModel)
 {
     var salt           = GenerateRandomNumbers.RandomNumbers(20);
     var saltedpassword = GenerateHashSha512.Sha512(resetPasswordViewModel.Password, salt);
 }