/// <summary>
        /// Get password by user code
        /// </summary>
        /// <param name="userCode">User code</param>
        /// <param name="error">Error</param>
        /// <returns>User</returns>
        public string GetPassword(string userCode, out ErrorMessage error)
        {
            var dateStart = DateTime.Now;

            Performancelog.Debug($"Start,LoginManager,GetPassword,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}");
            error = new ErrorMessage();
            if (_policyManager.WINDOWS_LOGIN)
            {
                if (string.IsNullOrEmpty(userCode))
                {
                    error = new ErrorMessage
                    {
                        MessageStyle = new MessageStyle {
                            Message = "Please provide userName"
                        },
                        StatusCode = HttpStatusCode.NotFound
                    };
                    return(null);
                }
                var user = _userService.GetUser(userCode.ToUpper());
                if (user == null)
                {
                    error = new ErrorMessage
                    {
                        MessageStyle = new MessageStyle
                        {
                            Message     = "You are Not Authorized to Login",
                            MessageType = MessageType.OkOnly
                        },
                        StatusCode  = HttpStatusCode.Unauthorized,
                        ShutDownPos = true
                    };
                    return(null);
                }
                //Add user in cache

                var pswd          = new EncryptionManager();
                var decryptedText = pswd.DecryptText(user.epw);
                user.Password = decryptedText;
                CacheManager.AddUser(userCode, user);
                Performancelog.Debug(
                    $"End,LoginManager,GetPassword,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
                return(user.Password);
            }
            error = new ErrorMessage
            {
                MessageStyle = new MessageStyle
                {
                    Message     = Utilities.Constants.InvalidRequest,
                    MessageType = MessageType.OkOnly
                },
                StatusCode  = HttpStatusCode.BadRequest,
                ShutDownPos = true
            };
            return(null);
        }
        /// <summary>
        /// Get the user by user code in cache
        /// </summary>
        /// <param name="userCode">User code</param>
        /// <returns>User</returns>
        public User GetExistingUser(string userCode)
        {
            var dateStart = DateTime.Now;

            Performancelog.Debug($"Start,LoginManager,GetExistingUser,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}");
            if (string.IsNullOrEmpty(userCode))
            {
                return(null);
            }
            var user = CacheManager.GetUser(userCode);

            if (user != null)
            {
                return(user);
            }
            user = GetUser(userCode);
            Performancelog.Debug($"End,LoginManager,GetExistingUser,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
            CacheManager.AddUser(userCode, user);
            return(user);
        }
        /// <summary>
        /// Checks User ID
        /// </summary>
        /// <param name="userName">Username</param>
        /// <param name="password">Password</param>
        /// <param name="posId">POS Id</param>
        /// <param name="unauthorizedAccess">Unauthorized access</param>
        /// <param name="message">Error</param>
        /// <returns>True or false</returns>
        private bool CheckUserId(string userName, string password, int posId,
                                 bool unauthorizedAccess, out ErrorMessage message)
        {
            var returnValue = true;

            message = new ErrorMessage();
            //var user = _userService.GetUser(userName);
            var user = CacheManager.GetUser(userName) ?? _userService.GetUser(userName);

            var encryptionManager = new EncryptionManager();

            if (user != null)
            {
                //Add user in Cache
                CacheManager.AddUser(userName, user);
                var offSet = _policyManager.LoadStoreInfo().OffSet;
                if (_policyManager.LogUnlimit == false)
                {
                    //User cannot log on to more than one register unless it is a Trainer
                    if (user.User_Group.Code != "Trainer" && !unauthorizedAccess)
                    {
                        var result = _loginService.CheckLoggedinUserPos(userName, posId);

                        if (result)
                        {
                            message = new ErrorMessage
                            {
                                MessageStyle = _resourceManager.CreateMessage(offSet, 30, 95, null, CriticalOkMessageType)
                            };
                            return(false);
                        }
                    }
                }
                if (!Convert.ToBoolean(_policyManager.GetPol("U_SELL", user)))
                {
                    //TIMsgbox "You are not authorized to sell products", _
                    //vbCritical + vbOKOnly, "No Authorization"
                    message = new ErrorMessage
                    {
                        MessageStyle = _resourceManager.CreateMessage(offSet, 30, 92, null, CriticalOkMessageType)
                    };
                }
                //End - SV

                if (!Convert.ToBoolean(_policyManager.GetPol("U_REQ_PW", user)))
                {
                    return(true);
                }
                if (password != encryptionManager.DecryptText(user.epw) || string.IsNullOrEmpty(password))
                {
                    message = new ErrorMessage
                    {
                        MessageStyle = _resourceManager.CreateMessage(offSet, 30, 91, null, CriticalOkMessageType)
                    };
                    returnValue = false;
                }
            }
            else
            {
                //TIMsgbox "UserID " & txtUserid.Text & " does not exist.", vbCritical + vbOKOnly, "No Such User", Me
                var offSet = _policyManager.LoadStoreInfo().OffSet;
                message = new ErrorMessage
                {
                    MessageStyle = _resourceManager.CreateMessage(offSet, 30, 93, userName, CriticalOkMessageType)
                };
                returnValue = false;
            }
            return(returnValue);
        }