Example #1
0
            /// <summary>
            /// Inserts the new user in to M_USERS.
            /// </summary>
            /// <param name="userName">Name of the user.</param>
            /// <param name="password">Password.</param>
            /// <param name="cardId">The card id.</param>
            /// <param name="userAuthenticationOn">The user authentication on.</param>
            /// <param name="pin">The pin.</param>
            /// <param name="authenticationMode">The authentication mode.</param>
            /// <param name="defaultDepartment">The default department.</param>
            /// <returns>string</returns>
            /// <remarks>
            /// Sequence Diagram:<br/>
            ///     <img src="SequenceDiagrams/SD_DataManagerDevice.Controller.Users.InsertUser.jpg"/>
            /// </remarks>
            public static string UpdateUser(string userName, string password, string cardId, string userAuthenticationOn, string pin, string authenticationMode, int defaultDepartment, string domainName, ref bool isUpdated)
            {
                isUpdated = false;
                string returnValue  = string.Empty;
                string hashPassword = Protector.ProvideEncryptedPassword(password);
                string hashPin      = string.Empty;
                string hashCardId   = string.Empty;

                if (!string.IsNullOrEmpty(pin))
                {
                    hashPin = Protector.ProvideEncryptedPin(pin);
                }
                if (!string.IsNullOrEmpty(cardId))
                {
                    hashCardId = Protector.ProvideEncryptedCardID(cardId);
                }
                string sqlQuery = "";

                isUpdated = true;
                sqlQuery  = "update M_USERS set USR_CARD_ID=N'" + hashCardId + "',USR_PASSWORD=N'" + hashPassword + "',USR_ATHENTICATE_ON=N'" + userAuthenticationOn + "' where USR_ID=N'" + userName + "' and USR_SOURCE=N'" + authenticationMode + "'";
                using (Database dbUser = new Database())
                {
                    DbCommand cmdUser = dbUser.GetSqlStringCommand(sqlQuery);
                    returnValue = dbUser.ExecuteNonQuery(cmdUser);
                }
                return(returnValue);
            }
Example #2
0
            /// <summary>
            /// Inserts the new user in to M_USERS.
            /// </summary>
            /// <param name="userName">Name of the user.</param>
            /// <param name="password">Password.</param>
            /// <param name="cardId">The card id.</param>
            /// <param name="userAuthenticationOn">The user authentication on.</param>
            /// <param name="pin">The pin.</param>
            /// <param name="authenticationMode">The authentication mode.</param>
            /// <param name="defaultDepartment">The default department.</param>
            /// <returns>string</returns>
            /// <remarks>
            /// Sequence Diagram:<br/>
            ///     <img src="SequenceDiagrams/SD_DataManagerDevice.Controller.Users.InsertUser.jpg"/>
            /// </remarks>
            public static string InsertUser(string userName, string password, string cardId, string userAuthenticationOn, string pin, string authenticationMode, int defaultDepartment, string domainName, string emailid, ref bool isUpdated)
            {
                isUpdated = false;
                string returnValue  = string.Empty;
                string hashPassword = Protector.ProvideEncryptedPassword(password);
                string hashPin      = string.Empty;
                string hashCardId   = string.Empty;

                if (!string.IsNullOrEmpty(pin))
                {
                    hashPin = Protector.ProvideEncryptedPin(pin);
                }
                if (!string.IsNullOrEmpty(cardId))
                {
                    hashCardId = Protector.ProvideEncryptedCardID(cardId);
                }

                string sqlQuery = "insert into M_USERS(USR_CARD_ID, USR_ID,USR_DOMAIN, USR_SOURCE, USR_NAME,USR_EMAIL, USR_PIN, USR_PASSWORD,USR_ATHENTICATE_ON,USR_DEPARTMENT,USR_ROLE, REC_CDATE, REC_ACTIVE)values(N'" + hashCardId + "',N'" + userName.Replace("'", "''") + "',N'" + domainName + "',N'" + authenticationMode + "' ,N'" + userName.Replace("'", "''") + "',N'" + emailid + "',N'" + hashPin + "',N'" + hashPassword + "',N'" + userAuthenticationOn + "',N'" + defaultDepartment + "','user', getdate(), 'True')";

                if (Users.IsRecordExists("M_USERS", "USR_ID", userName, authenticationMode))
                {
                    isUpdated = true;
                    sqlQuery  = "update M_USERS set USR_CARD_ID=N'" + hashCardId + "',USR_PASSWORD=N'" + hashPassword + "',USR_PIN=N'" + hashPin + "',USR_ATHENTICATE_ON=N'" + userAuthenticationOn + "' where USR_ID=N'" + userName + "' and USR_SOURCE=N'" + authenticationMode + "'";
                }
                using (Database dbUser = new Database())
                {
                    DbCommand cmdUser = dbUser.GetSqlStringCommand(sqlQuery);
                    returnValue = dbUser.ExecuteNonQuery(cmdUser);
                }
                return(returnValue);
            }
        /// <summary>
        /// Handles the Click event of the ButtonFutureLogin control.
        /// </summary>
        /// <param name="sender">Source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/>Instance containing the event data.</param>
        /// <remarks>
        /// Sequence Diagram:<br/>
        ///     <img src="SequenceDiagrams/SD_PrintReleaseDevice.Browser.SelfRegistration.ButtonFutureLogin_Click.jpg"/>
        /// </remarks>
        protected void LinkButtonFutureLogOn_Click(object sender, EventArgs e)
        {
            string pinNumber = TextBoxPin.Text.Trim();

            if (RadioButtonUseWindowsPassword.Checked)
            {
                AddUserDetails();
            }
            else
            {
                if (!string.IsNullOrEmpty(pinNumber))
                {
                    if (!ApplicationHelper.IsInteger(pinNumber))
                    {
                        redirectToLogOn                  = false;
                        TableCommunicator.Visible        = true;
                        TableFutureLogOnControls.Visible = false;
                        LabelCommunicatorNote.Text       = Localization.GetServerMessage(Constants.APPLICATION_TYPE_OSA_CLASSIC, deviceCulture, "INVALID_USER_PIN");
                    }
                    else
                    {
                        int pinLength = pinNumber.Length;
                        if (pinLength >= 4 && pinLength <= 10)
                        {
                            string hashedPin = Protector.ProvideEncryptedPin(pinNumber);
                            if (!DataManagerDevice.Controller.Users.IsPinExists(hashedPin))
                            {
                                AddUserDetails();
                            }
                            else
                            {
                                redirectToLogOn                  = false;
                                TableCommunicator.Visible        = true;
                                TableFutureLogOnControls.Visible = false;
                                LabelCommunicatorNote.Text       = Localization.GetServerMessage(Constants.APPLICATION_TYPE_OSA_CLASSIC, deviceCulture, "PIN_ALREADY_USED");
                            }
                        }
                        else
                        {
                            redirectToLogOn                  = false;
                            TableCommunicator.Visible        = true;
                            TableFutureLogOnControls.Visible = false;
                            LabelCommunicatorNote.Text       = Localization.GetServerMessage(Constants.APPLICATION_TYPE_OSA_CLASSIC, deviceCulture, "PIN_MINIMUM");
                        }
                    }
                }
                else
                {
                    redirectToLogOn                  = false;
                    TableCommunicator.Visible        = true;
                    TableFutureLogOnControls.Visible = false;
                    LabelCommunicatorNote.Text       = Localization.GetServerMessage(Constants.APPLICATION_TYPE_OSA_CLASSIC, deviceCulture, "ENTER_VALDI_PIN");
                }
            }
        }
Example #4
0
 /// <summary>
 /// Updates the user details.
 /// </summary>
 /// <remarks>
 /// Sequence Diagram:<br/>
 ///     <img src="SequenceDiagrams/SD_WebMyProfile.UpdateUserDetails.jpg"/>
 /// </remarks>
 private void UpdateUserDetails()
 {
     try
     {
         string userID          = TextBoxUserID.Text.Trim();
         string userName        = TextBoxName.Text.Trim();
         string userPin         = TextBoxPin.Text.Trim();
         string userEmail       = TextBoxEmail.Text.Trim();
         string hashedPassword  = string.Empty;
         string hashedPinNumber = string.Empty;
         string userCostCenter  = DropDownListCostCenters.SelectedValue;
         if (DBPassword == TextBoxPassword.Text.Trim())
         {
             hashedPassword = DBPassword;
         }
         else
         {
             hashedPassword = Protector.ProvideEncryptedPassword(TextBoxPassword.Text.Trim());
         }
         string sqlAddonFilter = string.Format(CultureInfo.CurrentCulture, " USR_ID <> '{0}'", userID);
         if (DBPinNumber == userPin)
         {
             hashedPinNumber = userPin;
         }
         else
         {
             hashedPinNumber = Protector.ProvideEncryptedPin(userPin);
             if (DataManager.Controller.Users.IsOtherRecordExists("M_USERS", "USR_PIN", hashedPinNumber, sqlAddonFilter))
             {
                 string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "PIN_ALREADY_USED");
                 GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Warning.ToString(), serverMessage, null);
                 return;
             }
         }
         string addSqlResponse = DataManager.Controller.Users.UpdateMyProfile(userID, userName, hashedPassword, hashedPinNumber, userEmail, userCostCenter);
         if (string.IsNullOrEmpty(addSqlResponse))
         {
             Session["UserName"] = userName;
             string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_PROFILE_UPDATE_SUCCESS");
             GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Success.ToString(), serverMessage, null);
             GetUserDetails();
         }
         else
         {
             string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_UPDATE_FAIL");
             GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null);
         }
     }
     catch
     {
     }
 }
Example #5
0
        /// <summary>
        /// Validates User password.
        /// </summary>
        /// <param name="userId">User id.</param>
        /// <param name="password">Password.</param>
        /// <param name="userDomain">User domain.</param>
        /// <remarks>
        /// Sequence Diagram:<br/>
        ///     <img src="SequenceDiagrams/SD_PrintReleaseEA.Mfp.ManualLogOn.ValidateUserPassword.jpg"/>
        /// </remarks>
        private void ValidateUserPassword(string userId, string password, string userDomain)
        {
            DataSet dsUserDetails = null;

            try
            {
                dsUserDetails = DataManagerDevice.ProviderDevice.Users.ProvideUserDetails(userId, userSource);
            }
            catch (Exception)
            {
                Response.Redirect("MessageForm.aspx?FROM=ManualLogOn.aspx&MESS=FailedToLogin");
                return;
            }

            if (dsUserDetails.Tables[0].Rows.Count > 0)
            {
                string hashedPin         = Protector.ProvideEncryptedPin(password);
                bool   userAccountActive = bool.Parse(dsUserDetails.Tables[0].Rows[0]["REC_ACTIVE"].ToString());
                if (userAccountActive)
                {
                    string isSaveNetworkPassword = Session["NETWORKPASSWORD"].ToString();
                    // Network password option is not required here. Since it is only applicable for Card Logon//
                    // Hence it is set to false.
                    isSaveNetworkPassword = "******";

                    // If user source is AD/DM and network password is not saved
                    // Then Authenticate user in Active Directory/Domain
                    if (userSource != Constants.USER_SOURCE_DB && isSaveNetworkPassword == "False")
                    {
                        //string applicationDomainName = DataManagerDevice.ProviderDevice.ApplicationSettings.ProvideDomainName();
                        string applicationDomainName = dsUserDetails.Tables[0].Rows[0]["USR_DOMAIN"].ToString();
                        if (applicationDomainName == userDomain)
                        {
                            // Validate users based on source
                            if (!AppLibrary.AppAuthentication.isValidUser(userId, password, userDomain, userSource))
                            {
                                if (allowedRetiresForLogin > 0)
                                {
                                    isPinRetry = false;
                                    CheckPasswordRetryCount(userId, allowedRetiresForLogin);
                                }
                                else
                                {
                                    Response.Redirect("MessageForm.aspx?FROM=ManualLogOn.aspx&MESS=InvalidPassword");
                                }
                                return;
                            }
                        }
                        else
                        {
                            Response.Redirect("MessageForm.aspx?FROM=ManualLogOn.aspx&MESS=InvalidDomain");
                            return;
                        }
                    }
                    else
                    {
                        // Check password is not null
                        // Encrypt the password && Compare with Database password field
                        if (!string.IsNullOrEmpty(password) && Protector.ProvideEncryptedPassword(password) != dsUserDetails.Tables[0].Rows[0]["USR_PASSWORD"].ToString())
                        {
                            if (allowedRetiresForLogin > 0)
                            {
                                isPinRetry = false;
                                CheckPasswordRetryCount(userId, allowedRetiresForLogin);
                            }
                            else
                            {
                                Response.Redirect("MessageForm.aspx?FROM=ManualLogOn.aspx&MESS=InvalidPassword");
                            }
                            return;
                        }
                    }
                    //}

                    string userSysID = dsUserDetails.Tables[0].Rows[0]["USR_ACCOUNT_ID"].ToString();
                    if (!string.IsNullOrEmpty(userSysID))
                    {
                        string DbuserID = dsUserDetails.Tables[0].Rows[0]["USR_ID"].ToString();
                        Session["PRServer"]     = "";
                        Session["UserID"]       = DbuserID;
                        Session["Username"]     = dsUserDetails.Tables[0].Rows[0]["USR_NAME"].ToString();
                        Session["UserSystemID"] = userSysID;
                        if (userSource != Constants.USER_SOURCE_DB)
                        {
                            string printJobDomainName = DataManagerDevice.ProviderDevice.ApplicationSettings.ProvideDomainName(userDomain);
                            Session["DomainName"] = printJobDomainName;
                        }
                        string createDate = dsUserDetails.Tables[0].Rows[0]["REC_CDATE"].ToString();
                        if (string.IsNullOrEmpty(createDate))
                        {
                            string updateCDate = DataManagerDevice.Controller.Users.UpdateCDate(userSysID);
                        }
                        RedirectPage();
                        return;
                    }
                }
                else
                {
                    Response.Redirect("MessageForm.aspx?FROM=ManualLogOn.aspx&MESS=AccountDisabled");
                }
            }
            else
            {
                Response.Redirect("MessageForm.aspx?FROM=ManualLogOn.aspx&MESS=invalidUserTryAgain");
            }
        }
Example #6
0
        /// <summary>
        /// Validates Secure card.
        /// </summary>
        /// <param name="cardID">Card ID.</param>
        /// <param name="password">Password.</param>
        /// <param name="userDomain">User domain.</param>
        /// <remarks>
        /// Sequence Diagram:<br/>
        ///     <img src="SequenceDiagrams/SD_PrintReleaseEA.Mfp.CardLogOn.ValidateSecureCard.jpg"/>
        /// </remarks>
        private void ValidateSecureCard(string cardID, string password, string userDomain)
        {
            bool isValidFascilityCode = false;
            bool isValidCard          = false;
            bool isCardExixts         = DataManagerDevice.Controller.Card.IsCardExists(cardID);

            if (isCardExixts)
            {
                string cardValidationInfo = "";
                string slicedCard         = Card.ProvideCardTransformation(null, Session["cardReaderType"] as string, cardID, ref isValidFascilityCode, ref isValidCard, ref cardValidationInfo);
                if (isValidFascilityCode && !string.IsNullOrEmpty(slicedCard))
                {
                    if (string.Compare(cardID, slicedCard, false) == 0) //cardID.IndexOf(sliceCard) > -1
                    {
                        DataSet dsCardDetails = DataManagerDevice.ProviderDevice.Users.ProvideCardUserDetails(cardID, userSource);
                        if (dsCardDetails.Tables[0].Rows.Count > 0)
                        {
                            //if (string.Compare(cardID, slicedCard, true) == 0) //cardID.IndexOf(sliceCard) > -1
                            //{

                            // Change the user source as per card ID;

                            string userCardSource = dsCardDetails.Tables[0].Rows[0]["USR_SOURCE"].ToString();
                            userSource            = userCardSource;
                            Session["UserSource"] = userSource;

                            bool isCardActive = bool.Parse(dsCardDetails.Tables[0].Rows[0]["REC_ACTIVE"].ToString());
                            domainName = dsCardDetails.Tables[0].Rows[0]["USR_DOMAIN"].ToString();
                            if (isCardActive)
                            {
                                allowedRetiresForLogin = int.Parse(DataManagerDevice.ProviderDevice.ApplicationSettings.ProvideSetting("Allowed retries for user login"), CultureInfo.CurrentCulture);
                                string userID = dsCardDetails.Tables[0].Rows[0]["USR_ID"].ToString();
                                Session["UserID"] = userID;
                                string hashedPin            = Protector.ProvideEncryptedPin(password);
                                string userAuthenticationOn = dsCardDetails.Tables[0].Rows[0]["USR_ATHENTICATE_ON"].ToString();
                                // Authenticate PIN based on User Future Login Selection
                                if (userAuthenticationOn == Constants.AUTHENTICATE_FOR_PIN)
                                {
                                    if (hashedPin != dsCardDetails.Tables[0].Rows[0]["USR_PIN"].ToString())
                                    {
                                        if (allowedRetiresForLogin > 0)
                                        {
                                            isPinRetry = true;
                                            CheckCardRetryCount(userID, allowedRetiresForLogin);
                                        }
                                        else
                                        {
                                            Session["CardID"] = null;
                                            Response.Redirect("MessageForm.aspx?FROM=Logon.aspx&MESS=invalidPin");
                                        }
                                        return;
                                    }
                                }
                                else
                                {
                                    string isSaveNetworkPassword = Session["NETWORKPASSWORD"].ToString();

                                    // If user source is AD/DM and network password is not saved
                                    // Then Authenticate user in Active Directory/Domain
                                    if (userSource != Constants.USER_SOURCE_DB && isSaveNetworkPassword == "False")
                                    {
                                        // Validate users based on source
                                        if (!AppAuthentication.isValidUser(userID, password, userDomain, userSource))
                                        {
                                            if (allowedRetiresForLogin > 0)
                                            {
                                                isPinRetry = false;
                                                CheckCardRetryCount(userID, allowedRetiresForLogin);
                                            }
                                            else
                                            {
                                                Session["CardID"] = null;
                                                Response.Redirect("MessageForm.aspx?FROM=Logon.aspx&MESS=InvalidPassword");
                                            }
                                            return;
                                        }
                                    }
                                    else
                                    {
                                        // Check password is not null
                                        // Encrypt the password && Compare with Database password field
                                        if (!string.IsNullOrEmpty(password) && Protector.ProvideEncryptedPassword(password) != dsCardDetails.Tables[0].Rows[0]["USR_PASSWORD"].ToString())
                                        {
                                            if (allowedRetiresForLogin > 0)
                                            {
                                                isPinRetry = false;
                                                CheckCardRetryCount(userID, allowedRetiresForLogin);
                                            }
                                            else
                                            {
                                                Session["CardID"] = null;
                                                Response.Redirect("MessageForm.aspx?FROM=Logon.aspx&MESS=InvalidPassword");
                                            }
                                            return;
                                        }
                                    }
                                }
                                string lastLogin = dsCardDetails.Tables[0].Rows[0]["REC_CDATE"].ToString();
                                if (string.IsNullOrEmpty(lastLogin) && userProvisioning == "First Time Use")
                                {
                                    if (!string.IsNullOrEmpty(dsCardDetails.Tables[0].Rows[0]["USR_NAME"].ToString()))
                                    {
                                        userID = dsCardDetails.Tables[0].Rows[0]["USR_NAME"].ToString();
                                    }
                                    Session["ftuUserID"]    = userID;
                                    Session["Username"]     = dsCardDetails.Tables[0].Rows[0]["USR_NAME"].ToString();
                                    Session["ftuUsersysID"] = dsCardDetails.Tables[0].Rows[0]["USR_ACCOUNT_ID"].ToString();
                                    string printJobDomainName = DataManagerDevice.ProviderDevice.ApplicationSettings.ProvideDomainName(domainName);
                                    Session["DomainName"] = printJobDomainName;
                                    Response.Redirect("FirstTimeUse.aspx");
                                }
                                string userSysID = dsCardDetails.Tables[0].Rows[0]["USR_ACCOUNT_ID"].ToString();
                                string DbuserID  = dsCardDetails.Tables[0].Rows[0]["USR_ID"].ToString();
                                if (DbuserID.ToLower() == "admin" || DbuserID.ToLower() == "administrator")
                                {
                                    Response.Redirect("MessageForm.aspx?FROM=CardLogOn.aspx&MESS=adminUserID");
                                    return;
                                }
                                Session["PRServer"]     = "";
                                Session["UserID"]       = DbuserID;
                                Session["Username"]     = dsCardDetails.Tables[0].Rows[0]["USR_NAME"].ToString();
                                Session["UserSystemID"] = userSysID;
                                if (userSource != Constants.USER_SOURCE_DB)
                                {
                                    string printJobDomainName = DataManagerDevice.ProviderDevice.ApplicationSettings.ProvideDomainName(domainName);
                                    Session["DomainName"] = printJobDomainName;
                                }
                                string createDate = dsCardDetails.Tables[0].Rows[0]["REC_CDATE"].ToString();
                                if (string.IsNullOrEmpty(createDate))
                                {
                                    string updateCDate = DataManagerDevice.Controller.Users.UpdateCDate(userSysID);
                                }
                                RedirectPage();
                                return;
                            }
                            else
                            {
                                Session["CardID"] = null;
                                Response.Redirect("MessageForm.aspx?FROM=Logon.aspx&MESS=AccountDisabled");
                            }
                        }
                        else
                        {
                            if (userProvisioning == "Self Registration" && userSource == "AD")
                            {
                                SelfRegisterCard();
                            }
                            else
                            {
                                Session["CardID"] = null;
                                Response.Redirect("MessageForm.aspx?FROM=Logon.aspx&MESS=cardInfoNotFoundConsultAdmin");
                            }
                        }
                    }
                    else
                    {
                        Session["CardID"] = null;
                        Response.Redirect("MessageForm.aspx?FROM=Logon.aspx&MESS=invalidCardId");
                    }
                }
                else
                {
                    if (!isValidFascilityCode)
                    {
                        Session["CardID"] = null;
                        Response.Redirect("MessageForm.aspx?FROM=Logon.aspx&MESS=invalidCardId");
                    }
                    else
                    {
                        if (userProvisioning == "Self Registration" && userSource == "AD")
                        {
                            SelfRegisterCard();
                        }
                        else
                        {
                            Session["CardID"] = null;
                            Response.Redirect("MessageForm.aspx?FROM=Logon.aspx&MESS=cardInfoNotFoundConsultAdmin");
                        }
                    }
                }
            }
            else
            {
                if (userProvisioning == "Self Registration" && userSource == "AD")
                {
                    SelfRegisterCard();
                }
                else
                {
                    Session["CardID"] = null;
                    Response.Redirect("MessageForm.aspx?FROM=Logon.aspx&MESS=cardInfoNotFoundConsultAdmin");
                }
            }
        }
        /// <summary>
        /// Adds the user details.
        /// </summary>
        /// <remarks>
        /// Sequence Diagram:<br/>
        ///     <img src="SequenceDiagrams/CD_PrintRoverWeb.AdministrationAddUsers.AddUserDetails.jpg"/>
        /// </remarks>
        private void AddUserDetails()
        {
            string userID               = TextBoxUserID.Text.Trim();
            string userName             = TextBoxName.Text;
            string userPassword         = TextBoxPassword.Text;
            string userPin              = TextBoxPin.Text;
            string userCardID           = TextBoxCard.Text;
            string userEmail            = TextBoxEmail.Text;
            bool   isLoginEnabled       = CheckBoxEnableLogOn.Checked;
            string userLoginEnabled     = "0";
            string userrole             = DropDown_UserRole.SelectedValue.ToLower().ToString();
            string userCostCenter       = DropDownListCostCenters.SelectedValue;
            string Department           = "1";
            string auditMessage         = string.Empty;
            string authenticationServer = "Local";
            string auditorSource        = HostIP.GetHostIP();
            string isMyAccount          = DropDownListMyAccount.SelectedValue;
            string userCommand          = TextBoxPin.Text;

            if (isLoginEnabled)
            {
                userLoginEnabled = "1";
            }

            if (userID.ToLower() != "admin" && userID.ToLower() != "administrator")
            {
                if (DataManager.Controller.Users.IsRecordExists("M_USERS", "USR_ID", userID, userSource))
                {
                    string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USERID_ALREADY_EXIST");
                    GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null);
                    return;
                }

                string hashExistPin = userPin;
                if (!string.IsNullOrEmpty(userPin))
                {
                    hashExistPin = Protector.ProvideEncryptedPin(userPin);
                    if (DataManager.Controller.Users.IsRecordExists("M_USERS", "USR_PIN", hashExistPin, userSource))
                    {
                        string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "PIN_ALREADY_USED");
                        GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null);
                        return;
                    }
                }

                if (!string.IsNullOrEmpty(userCardID))
                {
                    if (DataManager.Controller.Users.IsRecordExists("M_USERS", "USR_CARD_ID", userCardID, userSource))
                    {
                        string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "CARD_CONFIGURED_ANOTHER_USER");
                        GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null);
                        return;
                    }
                }

                try
                {
                    string addSqlResponse = DataManager.Controller.Users.AddUserDetails(userID, userName, userPassword, userCardID, userPin, userEmail, userLoginEnabled, DropDownPrintProfile.SelectedValue, userrole, Department, authenticationServer, userCostCenter, isMyAccount, userCommand);
                    if (string.IsNullOrEmpty(addSqlResponse))
                    {
                        //string assignUser = DataManager.Controller.Users.AssignUserToCostCenter(userID, "1", userSource);
                        auditMessage = "User " + userID + " Added successfully";
                        LogManager.RecordMessage(auditorSource, Session["UserID"] as string, LogManager.MessageType.Success, auditMessage);
                        string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_ADD_SUCCESS");
                        GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Success.ToString(), serverMessage, null);
                        //GenerateUserPin();
                        ClearControls();
                        GetUserDetails();

                        return;
                    }
                }
                catch (Exception ex)
                {
                    auditMessage = userID + " Failed to Add User";
                    LogManager.RecordMessage(auditorSource, Session["UserID"] as string, LogManager.MessageType.CriticalError, auditMessage, null, ex.Message, ex.StackTrace);
                    //PrintRoverWeb.Auditor.RecordMessage(Session["UserID"] as string, PrintRoverWeb.Auditor.MessageType.CriticalError, auditMessage, null, ex.Message, ex.StackTrace);
                    string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_ADD_FAIL");
                    GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null);
                    throw;
                }
            }
            else
            {
                auditMessage = userID + " Failed to Add User";
                LogManager.RecordMessage(auditorSource, Session["UserID"] as string, LogManager.MessageType.Warning, auditMessage);
                //PrintRoverWeb.Auditor.RecordMessage(Session["UserID"] as string, PrintRoverWeb.Auditor.MessageType.CriticalError, auditMessage, null, ex.Message, ex.StackTrace);
                string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_ADMIN_ERROR");
                GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Warning.ToString(), serverMessage, null);
                return;
            }
        }
        /// <summary>
        /// Updates the user details.
        /// </summary>
        /// <remarks>
        /// Sequence Diagram:<br/>
        ///     <img src="SequenceDiagrams/CD_PrintRoverWeb.AdministrationAddUsers.UpdateUserDetails.jpg"/>
        /// </remarks>
        private void UpdateUserDetails()
        {
            string userAccountId    = HdUserID.Value;
            string userID           = TextBoxUserID.Text.Trim();
            string userName         = TextBoxName.Text;
            string userPassword     = TextBoxPassword.Text;
            string userPin          = TextBoxPin.Text;
            string userCardID       = TextBoxCard.Text;
            string userEmail        = TextBoxEmail.Text;
            bool   isLoginEnabled   = CheckBoxEnableLogOn.Checked;
            string userLoginEnabled = "0";
            string userRole         = DropDown_UserRole.SelectedItem.Value.ToLower().ToString();
            string userCostCenter   = DropDownListCostCenters.SelectedValue;
            string department       = "1";
            //DropDownDepartment.SelectedValue;
            string authenticationMode   = string.Empty;
            string hashedPinNumber      = string.Empty;
            string auditMessage         = string.Empty;
            string authenticationServer = "Local";
            string auditorSource        = HostIP.GetHostIP();
            string isMyAccount          = DropDownListMyAccount.SelectedValue;
            string userCommand          = TextBoxPin.Text;

            if (isLoginEnabled)
            {
                userLoginEnabled = "1";
            }
            if (DropDown_UserRole.SelectedIndex == 0)
            {
                string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "SELECT_USER_ROLE");
                GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null);
                return;
            }

            //DataSet dsUserDetails = DataManager.Provider.Users.provideSelectedUserDetails(userID, userSource);
            DataSet dsUserDetails = DataManager.Provider.Users.provideSelectedUserDetails(userAccountId, userSource);

            if (TextBoxPassword.Text != Convert.ToString(dsUserDetails.Tables[0].Rows[0]["USR_PASSWORD"], CultureInfo.CurrentUICulture))
            {
                userPassword = Protector.ProvideEncryptedPassword(userPassword);
            }

            if (!string.IsNullOrEmpty(userCardID))
            {
                if (TextBoxCard.Text != Convert.ToString(dsUserDetails.Tables[0].Rows[0]["USR_CARD_ID"], CultureInfo.CurrentUICulture))
                {
                    if (DataManager.Controller.Card.IsCardExists(userCardID, userID))
                    {
                        string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "CARD_CONFIGURED_ANOTHER_USER");
                        GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null);
                        return;
                    }
                    else
                    {
                        userCardID = Protector.ProvideEncryptedCardID(userCardID);
                    }
                }
            }
            string sqlAddonFilter = string.Format(CultureInfo.CurrentCulture, " USR_ID <> '{0}'", userID);

            if (!string.IsNullOrEmpty(userPin))
            {
                if (TextBoxPin.Text != Convert.ToString(dsUserDetails.Tables[0].Rows[0]["USR_PIN"], CultureInfo.CurrentUICulture))
                {
                    hashedPinNumber = Protector.ProvideEncryptedPin(TextBoxPin.Text);
                    if (DataManager.Controller.Users.IsOtherRecordExists("M_USERS", "USR_PIN", hashedPinNumber, sqlAddonFilter))
                    {
                        string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "PIN_ALREADY_USED");
                        GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage, null);
                        return;
                    }
                }
                else
                {
                    hashedPinNumber = TextBoxPin.Text;
                }
            }
            else
            {
                hashedPinNumber = TextBoxPin.Text;
            }
            try
            {
                string addSqlResponse = DataManager.Controller.Users.UpdateUserDetails(userSource, userAccountId, userName, userPassword, hashedPinNumber, userCardID, userEmail, userLoginEnabled, true, DropDownPrintProfile.SelectedValue, userRole, department, userCostCenter, isMyAccount, userCommand);

                if (string.IsNullOrEmpty(addSqlResponse))
                {
                    auditMessage = "User " + userID + " updated successfully";
                    LogManager.RecordMessage(auditorSource, Session["UserID"] as string, LogManager.MessageType.Success, auditMessage);
                    string serverMessage = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_UPDATE_SUCCESS");
                    GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Success.ToString(), serverMessage, null);
                    GetUserDetails();
                    return;
                }
            }
            catch (Exception ex)
            {
                auditMessage = userID + " Failed to update User";
                LogManager.RecordMessage(auditorSource, Session["UserID"] as string, LogManager.MessageType.CriticalError, auditMessage, null, ex.Message, ex.StackTrace);
                string serverMessage1 = Localization.GetServerMessage("", Session["selectedCulture"] as string, "USER_UPDATE_FAIL");
                GetMasterPage().DisplayActionMessage(AppLibrary.MessageType.Error.ToString(), serverMessage1, null);
                return;
            }
        }