public bool Post([FromBody] ChangePasswordModel ChangePasswordModel)
        {
            try
            {
                var UserID = (from user in _DatabaseContext.UserMasterTB
                              where user.Username == ChangePasswordModel.Username
                              select user.U_Id).SingleOrDefault();

                if (Comparepassword(ChangePasswordModel))
                {
                    string newEncrypttpassword = EncryptionLibrary.EncryptText(ChangePasswordModel.NewPassword);

                    var UserModel = new UserMasterTB {
                        U_Id = UserID, Password = newEncrypttpassword
                    };

                    var db = _DatabaseContext;
                    db.UserMasterTB.Attach(UserModel);
                    db.Entry(UserModel).Property(x => x.Password).IsModified = true;
                    db.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #2
0
        public ActionResult Register(RegisteredUser user)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View("Register", user));
                }
                if (_registeruserRepo.ValidateRegisteredUser(user))
                {
                    ModelState.AddModelError("", @"User is already registered");
                    return(View("Register", user));
                }

                user.CreatedOn = DateTime.Now;

                user.Password = EncryptionLibrary.EncryptText(user.Password);

                user.ActiveStatus = true;

                user.UserType = 1;

                _registeruserRepo.Add(user);

                TempData["UserManager"] = "User registered successfully";
                ModelState.Clear();
                return(RedirectToAction("Login"));
            }
            catch (Exception e)
            {
                //Console.WriteLine(e);
                //throw;
                return(View());
            }
        }
        public IActionResult Registration(Registration Registration)
        {
            try
            {
                var isUsernameExists = CheckUserNameExists(Registration.Username);

                if (isUsernameExists)
                {
                    ModelState.AddModelError("", errorMessage: "Username Already Used try unique one!");
                }
                else
                {
                    Registration.CreatedOn       = DateTime.Now;
                    Registration.RoleID          = 1;
                    Registration.Password        = EncryptionLibrary.EncryptText(Registration.Password);
                    Registration.ConfirmPassword = EncryptionLibrary.EncryptText(Registration.ConfirmPassword);
                    if (AddUser(Registration) > 0)
                    {
                        TempData["MessageRegistration"] = "Data Saved Successfully!";
                        return(View(Registration));
                    }
                    else
                    {
                        return(View(Registration));
                    }
                }

                return(View(Registration));
            }
            catch (System.Exception)
            {
                throw;
            }
        }
Example #4
0
 public IHttpActionResult Login(LoginViewModel loginViewModel)
 {
     if (!string.IsNullOrWhiteSpace(loginViewModel.Username) && !string.IsNullOrWhiteSpace(loginViewModel.Password))
     {
         var Username = loginViewModel.Username;
         var password = EncryptionLibrary.EncryptText(loginViewModel.Password);
         var result   = LoginRepository.ValidateUser(Username, password);
         if (result != null)
         {
             var RoleID   = result.RoleID;
             var roleCode = RoleRepository.GetRoleCode(RoleID);
             loginViewModel.RoleCode = roleCode;
             loginViewModel.UserId   = result.RegistrationID;
             if (!AssignRolesRepository.CheckIsUserAssignedRole(result.RegistrationID))
             {
                 loginViewModel.IsAssigned = false;
             }
             else
             {
                 loginViewModel.IsAssigned = true;
             }
         }
     }
     return(Ok(loginViewModel));
 }
        public IActionResult Registration(Registration Registration)
        {
            try
            {
                var isUsernameExists = _IRepository.CheckUserNameExists(Registration.Username);

                if (isUsernameExists)
                {
                    ModelState.AddModelError("", errorMessage: "Username Already Used try unique one!");
                }
                else
                {
                    Registration.CreatedOn       = DateTime.Now;
                    Registration.RoleID          = _IRoles.getRolesofUserbyRolename("Users");
                    Registration.Password        = EncryptionLibrary.EncryptText(Registration.Password);
                    Registration.ConfirmPassword = EncryptionLibrary.EncryptText(Registration.ConfirmPassword);
                    if (_IRepository.AddUser(Registration) > 0)
                    {
                        TempData["MessageRegistration"] = "You have successfully registered!";
                        ModelState.Clear();
                        return(View(new Registration()));
                    }
                    else
                    {
                        return(View(Registration));
                    }
                }

                return(View(Registration));
            }
            catch (System.Exception)
            {
                throw;
            }
        }
        public bool Post([FromBody] UserMasterTB usermastertb)
        {
            try
            {
                var output = (from usermaster in _DatabaseContext.UserMasterTB
                              where usermastertb.Username == usermaster.Username
                              select usermaster.Username).Count();

                if (output > 0)
                {
                    return(false);
                }
                else
                {
                    var userTypeID = (from user in _DatabaseContext.UserType
                                      where user.UserTypeName == "User"
                                      select user.UserTypeID).SingleOrDefault();
                    usermastertb.U_Id       = 0;
                    usermastertb.UserTypeID = userTypeID;
                    usermastertb.Password   = EncryptionLibrary.EncryptText(usermastertb.Password);
                    usermastertb.CreatedOn  = DateTime.Now;
                    _DatabaseContext.Add(usermastertb);
                    _DatabaseContext.SaveChanges();

                    return(true);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #7
0
        public ActionResult Create(RegisterUser RegisterUser)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View("Create", RegisterUser));
                }

                // Validating Username
                if (_repository.ValidateUsername(RegisterUser))
                {
                    ModelState.AddModelError("", "User is Already Registered");
                    return(View("Create", RegisterUser));
                }
                RegisterUser.CreateDate = DateTime.Now;

                // Encrypting Password with AES 256 Algorithm
                RegisterUser.Password = EncryptionLibrary.EncryptText(RegisterUser.Password);

                // Saving User Details in Database
                _repository.Add(RegisterUser);
                TempData["UserMessage"] = "User Registered Successfully";
                ModelState.Clear();
                return(View("Create", new RegisterUser()));
            }
            catch
            {
                return(View());
            }
        }
        public int Post([FromBody] UserDetails userDetails)
        {
            try
            {
                var output = (from userDetail in _DatabaseContext.UserDetails
                              where userDetail.Username == userDetails.Username
                              select userDetail.Username).Count();

                if (output > 0)
                {
                    return(0);
                }
                else
                {
                    var userTypeID = (from user in _DatabaseContext.UserType
                                      where user.UserTypeName == "User"
                                      select user.UserTypeID).SingleOrDefault();
                    userDetails.UserId     = 0;
                    userDetails.UserTypeID = userTypeID;
                    userDetails.Password   = EncryptionLibrary.EncryptText(userDetails.Password);
                    userDetails.CreatedOn  = DateTime.Now;
                    _DatabaseContext.Add(userDetails);
                    _DatabaseContext.SaveChanges();

                    return(userDetails.UserId);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #9
0
        public async Task <CustomerModel> ValidateCustomer(string username, string password)
        {
            var customer = await GetCustomerByUsername(username);

            if (customer == null)
            {
                return(null);
            }

            if (customer.Deleted)
            {
                return(null);
            }

            if (!customer.Active)
            {
                return(null);
            }

            if (!customer.Password.Equals(EncryptionLibrary.EncryptText(password)))
            {
                customer.FailedLoginAttempts++;
                if (customer.FailedLoginAttempts > 0 && customer.FailedLoginAttempts >= 5)
                {
                    //todo: lock account for 24 hours
                }
                await UpdateCustomer(customer);

                return(null);
            }

            return(_mapper.Map <CustomerModel>(customer));
        }
        public int RegistrarUsuario(User request)
        {
            request.Password = EncryptionLibrary.EncryptText(request.Password);
            int id = _UsersRepository.Insertar(request);

            return(id);
        }
        public IActionResult Create(UsersViewModel entity)
        {
            try
            {
                var isUsernameExists = _IRepository.CheckUserNameExists(entity.dbModel.Username);

                if (isUsernameExists)
                {
                    ModelState.AddModelError("", errorMessage: "Username already exists. Please enter a unique username.");
                }
                else
                {
                    entity.dbModel.CreatedOn       = DateTime.Now;
                    entity.dbModel.RoleID          = entity.dbModel.RoleID;
                    entity.dbModel.Password        = EncryptionLibrary.EncryptText(entity.dbModel.Password);
                    entity.dbModel.ConfirmPassword = EncryptionLibrary.EncryptText(entity.dbModel.Password);
                    if (_IRepository.AddUser(entity.dbModel) > 0)
                    {
                        TempData["MessageRegistration"] = "User created successfully!";
                        // return View(entity.dbModel);
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        return(RedirectToAction("Index"));
                    }
                }

                return(RedirectToAction("Index"));
            }
            catch (System.Exception)
            {
                throw;
            }
        }
Example #12
0
        public ActionResult Register(Registration registration)
        {
            try
            {
                UserManager userManager = new UserManager();


                registration.CreatedBy = Session["Username"].ToString();
                registration.Password  = EncryptionLibrary.EncryptText(registration.Password);
                int value = userManager.CreateUser(registration);
                if (value == 1)
                {
                    TempData["MessageRegistration"] = "User Created Successfully";
                    return(RedirectToAction("/Index"));
                }
                else if (value == 2)
                {
                    TempData["MessageRegistration"] = " EmailID already exist";
                }
                else if (value == 3)
                {
                    TempData["MessageRegistration"] = " Username already exist";
                }
                else if (value == 0)
                {
                    TempData["MessageRegistration"] = "Error Occured";
                }
                // ViewBag.Roles = new SelectList(userManager.GetRoleList(), "RoleID", "RoleName");
                return(RedirectToAction("/Index"));
            }
            catch
            {
                return(View());
            }
        }
Example #13
0
        public ActionResult CreateAdmin(Registration registration)
        {
            try
            {
                var isUsernameExists = _IRegistration.CheckUserNameExists(registration.Username);

                if (isUsernameExists)
                {
                    ModelState.AddModelError("", errorMessage: "Username Already Used try unique one!");
                }
                else
                {
                    registration.CreatedOn       = DateTime.Now;
                    registration.RoleID          = _IRoles.getRolesofUserbyRolename("Admin");
                    registration.Password        = EncryptionLibrary.EncryptText(registration.Password);
                    registration.ConfirmPassword = EncryptionLibrary.EncryptText(registration.ConfirmPassword);
                    if (_IRegistration.AddUser(registration) > 0)
                    {
                        TempData["MessageRegistration"] = "Data Saved Successfully!";
                        return(RedirectToAction("CreateAdmin"));
                    }
                    else
                    {
                        return(View("CreateAdmin", registration));
                    }
                }

                return(RedirectToAction("Dashboard"));
            }
            catch
            {
                return(View());
            }
        }
Example #14
0
        public JsonResult ResetUserPasswordProcess(string RegistrationID)
        {
            try
            {
                if (string.IsNullOrEmpty(Convert.ToString(RegistrationID)))
                {
                    return(Json("Error", JsonRequestBehavior.AllowGet));
                }

                var Password          = EncryptionLibrary.EncryptText("default@123");
                var isPasswordUpdated = _IRegistration.UpdatePassword(RegistrationID, Password);

                if (isPasswordUpdated)
                {
                    return(Json(data: true, behavior: JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(data: false, behavior: JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #15
0
        public ActionResult ChangePassword(ChangePasswordModel changepasswordmodel)
        {
            try
            {
                var password = EncryptionLibrary.EncryptText(changepasswordmodel.OldPassword);

                var storedPassword = _ILogin.GetPasswordbyUserID(Convert.ToInt32(Session["UserID"]));

                if (storedPassword == password)
                {
                    var result = _ILogin.UpdatePassword(EncryptionLibrary.EncryptText(changepasswordmodel.NewPassword), Convert.ToInt32(Session["UserID"]));

                    if (result)
                    {
                        ModelState.Clear();
                        ViewBag.message = "Password Changed Successfully";
                        return(View(changepasswordmodel));
                    }
                    else
                    {
                        ModelState.AddModelError("", "Something Went Wrong Please try Again after some time");
                        return(View(changepasswordmodel));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Entered Wrong Old Password");
                    return(View(changepasswordmodel));
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #16
0
        public IActionResult ChangePassword(ChangePasswordModel ChangePasswordModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(ChangePasswordModel));
            }

            var password          = EncryptionLibrary.EncryptText(ChangePasswordModel.Password);
            var registrationModel = _IUsers.Userinformation(Convert.ToInt32(HttpContext.Session.GetString("UserID")));

            if (registrationModel.Password == password)
            {
                var registration = new Users();
                registration.Password = EncryptionLibrary.EncryptText(ChangePasswordModel.NewPassword);
                registration.ID       = Convert.ToInt32(HttpContext.Session.GetString("UserID"));
                var result = _ILogin.UpdatePassword(registration);

                if (result)
                {
                    TempData["MessageUpdate"] = "Password Updated Successfully";
                    ModelState.Clear();
                    return(View(new ChangePasswordModel()));
                }
                else
                {
                    return(View(ChangePasswordModel));
                }
            }
            else
            {
                TempData["MessageUpdate"] = "Invalid Password";
                return(View(ChangePasswordModel));
            }
        }
Example #17
0
        public IActionResult Post([FromBody] LoginRequestViewModel value)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var loginstatus = _users.AuthenticateUsers(value.UserName,
                                                               EncryptionLibrary.EncryptText(value.Password));

                    if (loginstatus)
                    {
                        var userdetails = _users.GetUserDetailsbyCredentials(value.UserName,
                                                                             EncryptionLibrary.EncryptText(value.Password));

                        if (userdetails != null)
                        {
                            // Jason Web Token (Jwt) security token handler
                            var tokenHandler = new JwtSecurityTokenHandler();
                            var key          = Encoding.ASCII.GetBytes(_appSettings.Secret);

                            var tokenDescriptor = new SecurityTokenDescriptor
                            {
                                Subject = new ClaimsIdentity(new Claim[]
                                {
                                    new Claim(ClaimTypes.Name, userdetails.UserId.ToString())
                                }),
                                Expires            = DateTime.UtcNow.AddDays(1),
                                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key),
                                                                            SecurityAlgorithms.HmacSha256Signature)
                            };
                            var token = tokenHandler.CreateToken(tokenDescriptor);
                            value.Token = tokenHandler.WriteToken(token);

                            // Remove password before returning
                            value.Password = null;
                            value.Usertype = userdetails.RoleId;

                            return(Ok(value));
                        }
                        else
                        {
                            value.Password = null;
                            value.Usertype = 0;
                            return(Ok(value));
                        }
                    }
                    value.Password = null;
                    value.Usertype = 0;
                    return(Ok(value));
                }
                value.Password = null;
                value.Usertype = 0;
                return(Ok(value));
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #18
0
        public Task <Users> Handle(NewUser request, CancellationToken cancellationToken)
        {
            var tempUsers = AutoMapper.Mapper.Map <Users>(request);

            tempUsers.CreatedDate = DateTime.Now;
            tempUsers.Createdby   = 1;
            tempUsers.Password    = EncryptionLibrary.EncryptText(request.Password);
            _users.InsertUsers(tempUsers);
            return(Task.FromResult(tempUsers));
        }
Example #19
0
        public ActionResult Login(User loginUser)
        {
            try
            {
                if (string.IsNullOrEmpty(loginUser.Username) && (string.IsNullOrEmpty(loginUser.Password)))
                {
                    ModelState.AddModelError("", "Enter Username and Password");
                }
                else if (string.IsNullOrEmpty(loginUser.Username))
                {
                    ModelState.AddModelError("", "Enter Username");
                }
                else if (string.IsNullOrEmpty(loginUser.Password))
                {
                    ModelState.AddModelError("", "Enter Password");
                }
                else
                {
                    loginUser.Password = EncryptionLibrary.EncryptText(loginUser.Password);
                    UserManager usermgr = new UserManager();
                    if (usermgr.ValidateRegisteredUser(loginUser))
                    {
                        var UserID       = usermgr.GetLoggedUserID(loginUser);
                        var UserFullName = usermgr.GetUserFullName(UserID);
                        var UserImage    = usermgr.GetUserImage(UserID);
                        var UserStatus   = usermgr.GetUserStatus(UserID);
                        if (UserStatus)
                        {
                            Session["UserID"] = UserID;
                            HttpContext.Session["UserFullName"] = UserFullName;
                            Session["UserImg"] = UserImage;
                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            ModelState.AddModelError("", "Inactive User Access. Please contact Administrator.");
                            return(View("Login", loginUser));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Invalid Username or Password.");
                        loginUser.Password        = "";
                        loginUser.ConfirmPassword = "";
                        return(View("Login", loginUser));
                    }
                }

                return(View("Login", loginUser));
            }
            catch
            {
                return(View());
            }
        }
        public Admin Post([FromBody] Login objLogin)
        {
            Admin objReturn = null;

            objLogin.Password = EncryptionLibrary.EncryptText(objLogin.Password);
            using (Admin_BAL objBAL = new Admin_BAL())
            {
                objReturn = objBAL.Validate(objLogin.EmailId, objLogin.Password);
            }

            return(objReturn);
        }
        public ActionResult Login(LoginViewModel loginViewModel)
        {
            try
            {
                if (!string.IsNullOrEmpty(loginViewModel.Username) && !string.IsNullOrEmpty(loginViewModel.Password))
                {
                    var Username = loginViewModel.Username;
                    var password = EncryptionLibrary.EncryptText(loginViewModel.Password);

                    var result = _ILogin.ValidateUser(Username, password);

                    if (result != null)
                    {
                        if (result.ID == 0 || result.ID < 0)
                        {
                            ViewBag.errormessage = "Entered Invalid Username and Password";
                        }
                        else
                        {
                            var RoleID = result.RoleID;
                            remove_Anonymous_Cookies(); //Remove Anonymous_Cookies

                            HttpContext.Session.SetString("UserID", Convert.ToString(result.ID));
                            HttpContext.Session.SetString("RoleID", Convert.ToString(result.RoleID));
                            HttpContext.Session.SetString("Username", Convert.ToString(result.Username));
                            if (RoleID == 1)
                            {
                                return(RedirectToAction("Dashboard", "Admin"));
                            }
                            else if (RoleID == 2)
                            {
                                return(RedirectToAction("Dashboard", "Customer"));
                            }
                            else if (RoleID == 3)
                            {
                                return(RedirectToAction("Dashboard", "SuperAdmin"));
                            }
                        }
                    }
                    else
                    {
                        ViewBag.errormessage = "Entered Invalid Username and Password";
                        return(View());
                    }
                }
                return(View());
            }
            catch (Exception)
            {
                throw;
            }
        }
        public IActionResult Put(int id, [FromBody] UserViewModel user)
        {
            if (ModelState.IsValid)
            {
                user.Password = EncryptionLibrary.EncryptText(user.Password); // as we have unencrepted password

                var model = AutoMapper.Mapper.Map <Users>(user);
                model.UserId      = id;
                model.CreatedDate = DateTime.Now;

                bool result = _users.UpdateUser(model);

                return(Ok(result));
            }
            return(BadRequest());
        }
Example #23
0
        ///<summary>
        ///This method is tagged save user button click event. It validates inputs and calls save user information to database method
        ///</summary>
        /// <returns></returns>
        ///
        private void BtnSave_Click(object sender, EventArgs e)
        {
            if (ValidateUserFormInputs())
            {
                var user = new Users
                {
                    EmpId              = txtEmpId.Text,
                    UserName           = txtUsername.Text.Trim(),
                    UserPassword       = EncryptionLibrary.EncryptText(txtPassword.Text.Trim(), txtUsername.Text.Trim()),
                    MustChangePassword = chkBxChangePassword.Checked,
                    IsAdmin            = chkBxIsAdmin.Checked,
                    IsDisabled         = chkBxIsDisabled.Checked
                };

                if (_addOrEdit == 'A')
                {
                    SaveUser(user);
                }
                else
                {
                    UpdateUser(user);
                }

                txtEmpId.Text               = string.Empty;
                txtEmpName.Text             = string.Empty;
                txtUsername.Text            = string.Empty;
                txtPassword.Text            = string.Empty;
                txtConfirmPassword.Text     = string.Empty;
                chkBxChangePassword.Checked = false;
                chkBxIsAdmin.Checked        = false;
                chkBxIsDisabled.Enabled     = false;

                txtUsername.Enabled         = false;
                txtPassword.Enabled         = false;
                txtConfirmPassword.Enabled  = false;
                chkBxChangePassword.Enabled = false;
                chkBxIsAdmin.Enabled        = false;
                chkBxIsDisabled.Enabled     = false;

                btnAdd.Enabled    = true;
                btnEdit.Enabled   = false;
                btnDelete.Enabled = false;
                btnSave.Enabled   = false;
                btnCancel.Enabled = false;
            }
        }
        public ActionResult Login(RegisterUser RegisterUser)
        {
            try
            {
                if (string.IsNullOrEmpty(RegisterUser.Username) && (string.IsNullOrEmpty(RegisterUser.Password)))
                {
                    ModelState.AddModelError("", "Enter Username and Password");
                }
                else if (string.IsNullOrEmpty(RegisterUser.Username))
                {
                    ModelState.AddModelError("", "Enter Username");
                }
                else if (string.IsNullOrEmpty(RegisterUser.Password))
                {
                    ModelState.AddModelError("", "Enter Password");
                }
                else
                {
                    RegisterUser.Password = EncryptionLibrary.EncryptText(RegisterUser.Password);

                    if (_IRegisterUser.ValidateRegisteredUser(RegisterUser))
                    {
                        var UserID = _IRegisterUser.GetLoggedUserID(RegisterUser);
                        Session["UserID"] = UserID;
                        return(RedirectToAction("Create", "RegisterCompany"));
                    }
                    else if (!_IRegisterUser.ValidateRegisteredUser(RegisterUser))
                    {
                        ModelState.AddModelError("", "Wrong Username or password.");
                        return(View("Login", RegisterUser));
                    }
                    else
                    {
                        ModelState.AddModelError("", "User is Already Registered");
                        return(View("Create", RegisterUser));
                    }
                }

                return(View("Login", RegisterUser));
            }
            catch
            {
                return(View());
            }
        }
        public HttpResponseMessage Post([FromBody] UserViewModel users)
        {
            if (ModelState.IsValid)
            {
                if (_users.CheckEmailExits(users.Email))
                {
                    HttpResponseMessage response = new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.Conflict
                    };

                    return(response);
                }
                else
                {
                    if (users != null)
                    {
                        string     userId    = User.FindFirstValue(ClaimTypes.Name);
                        UserMaster tempUsers = Mapper.Map <UserMaster>(users);
                        tempUsers.IsActive    = true;
                        tempUsers.CreatedDate = DateTime.Now;
                        tempUsers.CreatedBy   = Convert.ToInt32(userId);
                        tempUsers.Password    = EncryptionLibrary.EncryptText(users.Password);
                        _users.InsertUsers(tempUsers);
                    }

                    HttpResponseMessage response = new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.OK
                    };

                    return(response);
                }
            }
            else
            {
                HttpResponseMessage response = new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.BadRequest
                };

                return(response);
            }
        }
Example #26
0
 public IHttpActionResult Login(RegisteredUser user)
 {
     try
     {
         if (string.IsNullOrEmpty(user.UserName) && string.IsNullOrEmpty(user.Password))
         {
             //ModelState.AddModelError("", @"Enter Username and Password");
             return(BadRequest(@"Enter Username and Password"));
         }
         else if (string.IsNullOrEmpty(user.UserName))
         {
             //ModelState.AddModelError("", @"Enter Username");
             return(BadRequest(@"Enter Username"));
         }
         else if (string.IsNullOrEmpty(user.Password))
         {
             //ModelState.AddModelError("", @"Enter Password");
             return(BadRequest(@"Enter Password"));
         }
         else
         {
             user.Password = EncryptionLibrary.EncryptText(user.Password);
             if (_registeruserRepo.ValidateRegisteredUser(user))
             {
                 var userId = _registeruserRepo.GetLoggedUserID(user);
                 //Session["UserId"] = userId;
                 //return RedirectToAction("GetProfile");
                 return(Ok <int>(userId));
             }
             else
             {
                 //ModelState.AddModelError("", @"User is already registered");
                 return(Ok <string>(@"User is already loged in"));
             }
         }
         //return View("Login", user);
     }
     catch (Exception e)
     {
         //Console.WriteLine(e);
         //throw;
         return(BadRequest());
     }
 }
        public string GenerateToken(ClientKey ClientKeys, DateTime IssuedOn)
        {
            try
            {
                string randomnumber =
                    string.Join(":", new string[]
                                { Convert.ToString(ClientKeys.UserID),
                                  KeyGenerator.GetUniqueKey(),
                                  Convert.ToString(ClientKeys.CompanyID),
                                  Convert.ToString(IssuedOn.Ticks),
                                  ClientKeys.ClientID });

                return(EncryptionLibrary.EncryptText(randomnumber));
            }
            catch (Exception)
            {
                throw;
            }
        }
        public string GenerateToken1(Applicationsdlp ApplicationsdlpKeys, DateTime IssuedOn)
        {
            try
            {
                string randomnumber =
                    string.Join(":", new string[]
                                { Convert.ToString(ApplicationsdlpKeys.Code),
                                  webzpitest.EncryptionLibrary.KeyGenerator.GetUniqueKey(),
                                  Convert.ToString(ApplicationsdlpKeys.AdmissionNo),
                                  Convert.ToString(IssuedOn.Ticks),
                                  ApplicationsdlpKeys.AdmissionNo });

                return(EncryptionLibrary.EncryptText(randomnumber));
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #29
0
        public int InsertData(MasterTable _master)
        {
            dbConnector   _dbconnector = new dbConnector();
            SqlConnection con          = _dbconnector.GetConnection;

            con.Open();
            try
            {
                if (con.State != ConnectionState.Open)
                {
                    con.Open();
                }
                var        _key   = EncryptionLibrary.EncryptText(_master.PassWord);
                SqlCommand _commd = new SqlCommand("Usp_InsertMaster", con);
                _commd.CommandType = CommandType.StoredProcedure;
                _commd.Parameters.AddWithValue("@UserID", 1);
                _commd.Parameters.AddWithValue("@Master_Name", _master.Master_Name);
                _commd.Parameters.AddWithValue("@Master_Email", _master.Master_Email);
                _commd.Parameters.AddWithValue("@PassWord", _key);
                _commd.Parameters.AddWithValue("@ImageId", _master.ImageId);
                _commd.Parameters.AddWithValue("@ContryId", _master.ContryId);
                _commd.Parameters.AddWithValue("@StateId", _master.StateId);
                _commd.Parameters.AddWithValue("@CityId", _master.CityId);
                int _finalresult = _commd.ExecuteNonQuery();
                //  int _finalresult =Convert.ToInt32( _commd.ExecuteScalar());
                return(_finalresult);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (con != null)
                {
                    if (con.State == ConnectionState.Open)
                    {
                        con.Close();
                    }
                }
            }
        }
Example #30
0
        public ActionResult Login(RegisterUser RegisterUser)
        {
            try
            {
                if (string.IsNullOrEmpty(RegisterUser.Username) && (string.IsNullOrEmpty(RegisterUser.Password)))
                {
                    ModelState.AddModelError("", "Enter Username and Password");
                }
                else if (string.IsNullOrEmpty(RegisterUser.Username))
                {
                    ModelState.AddModelError("", "Enter Username");
                }
                else if (string.IsNullOrEmpty(RegisterUser.Password))
                {
                    ModelState.AddModelError("", "Enter Password");
                }
                else
                {
                    RegisterUser.Password = EncryptionLibrary.EncryptText(RegisterUser.Password);

                    if (_IRegisterUser.ValidateRegisteredUser(RegisterUser))
                    {
                        var UserID = _IRegisterUser.GetLoggedUserID(RegisterUser);
                        HttpContext.Session.SetString("UserID", Convert.ToString(UserID));

                        return(RedirectToAction("Dashboard", "Dashboard"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "User is Already Registered");
                        return(View("Login", RegisterUser));
                    }
                }

                return(View("Login", RegisterUser));
            }
            catch (Exception)
            {
                return(View());
            }
        }