SebWindowsClient.ConfigurationUtils.SEBConfigFileManager.askForPasswordAndCompareToHashedPassword C# (CSharp) Method

askForPasswordAndCompareToHashedPassword() private static method

Ask user to enter password and compare it to the passed (hashed) password string Returns true if correct password was entered
private static askForPasswordAndCompareToHashedPassword ( string sebFileHashedAdminPassword, bool forEditing ) : bool
sebFileHashedAdminPassword string
forEditing bool
return bool
        private static bool askForPasswordAndCompareToHashedPassword(string sebFileHashedAdminPassword, bool forEditing)
        {
            // Check if there wasn't a hashed password (= empty password)
            if (sebFileHashedAdminPassword.Length == 0) return true;
            // We have to ask for the SEB administrator password used in the settings
            // and allow opening settings only if the user enters the right one
            // Allow up to 5 attempts for entering  admin password
            int i = 5;
            string password = null;
            string hashedPassword;
            string enterPasswordString = SEBUIStrings.enterAdminPasswordRequired;
            bool passwordsMatch;
            do
            {
                i--;
                // Prompt for password
                password = ThreadedDialog.ShowPasswordDialogForm(SEBUIStrings.loadingSettings + (String.IsNullOrEmpty(SEBClientInfo.LoadingSettingsFileName) ? "" : ": " + SEBClientInfo.LoadingSettingsFileName), enterPasswordString);
                // If cancel was pressed, abort
                if (password == null) return false;
                if (password.Length == 0)
                {
                    hashedPassword = "";
                }
                else
                {
                    hashedPassword = SEBProtectionController.ComputePasswordHash(password);
                }
                passwordsMatch = (String.Compare(hashedPassword, sebFileHashedAdminPassword, StringComparison.OrdinalIgnoreCase) == 0);
                // in case we get an error we allow the user to try it again
                enterPasswordString = SEBUIStrings.enterAdminPasswordRequiredAgain;
            } while ((password == null || !passwordsMatch) && i > 0);
            if (!passwordsMatch)
            {
                //wrong password entered in 5th try: stop reading .seb file
                SEBMessageBox.Show(SEBUIStrings.loadingSettingsFailed, SEBUIStrings.loadingSettingsFailedWrongAdminPwd, MessageBoxIcon.Error, MessageBoxButtons.OK, neverShowTouchOptimized: forEditing);
                return false;
            }
            // Right password entered
            return passwordsMatch;
        }

Usage Example

        private static Dictionary <string, object> GetPreferencesDictFromConfigData(byte[] sebData, bool forEditing)
        {
            Dictionary <string, object> dictionary;

            try
            {
                dictionary = (Dictionary <string, object>)Plist.readPlist(sebData);
            }
            catch (Exception ex)
            {
                int num = (int)SEBMessageBox.Show(SEBUIStrings.loadingSettingsFailed, SEBUIStrings.loadingSettingsFailedReason, MessageBoxIcon.Hand, MessageBoxButtons.OK, forEditing);
                Console.WriteLine(ex.Message);
                return((Dictionary <string, object>)null);
            }
            if (forEditing)
            {
                string str = (string)SEBSettings.valueForDictionaryKey(dictionary, "hashedAdminPassword");
                if (!string.IsNullOrEmpty(str) && (string.Compare((string)SEBSettings.valueForDictionaryKey(SEBSettings.settingsCurrent, "hashedAdminPassword") ?? "", str, StringComparison.OrdinalIgnoreCase) != 0 && !SEBConfigFileManager.askForPasswordAndCompareToHashedPassword(str, forEditing)))
                {
                    return((Dictionary <string, object>)null);
                }
            }
            return(dictionary);
        }
All Usage Examples Of SebWindowsClient.ConfigurationUtils.SEBConfigFileManager::askForPasswordAndCompareToHashedPassword