mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-25 11:50:31 +08:00
GP-5579 expose PasswordDialog userID preference key generation method
for testing.
This commit is contained in:
@@ -266,9 +266,27 @@ public class PasswordDialog extends DialogComponentProvider {
|
||||
// setInitialLocation( centerPoint.x, centerPoint.y );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link Preferences} key used to retain the last used user ID for a specific server.
|
||||
* Values supplied must match those used to instantiate password dialog.
|
||||
* @param serverType server type string
|
||||
* @param serverName server name (e.g., hostname, IP address).
|
||||
* @return preference key
|
||||
*/
|
||||
public static String getPreferredUserIdPreferenceKey(String serverType, String serverName) {
|
||||
return "UserID_" + sanitizeString(serverType) + "_" + sanitizeString(serverName);
|
||||
}
|
||||
|
||||
private static String sanitizeString(String str) {
|
||||
if (str == null) {
|
||||
return "_";
|
||||
}
|
||||
String newStr = str.replaceAll("[^a-zA-Z0-9_-]", "");
|
||||
return newStr.length() == 0 ? "_" : newStr;
|
||||
}
|
||||
|
||||
private String getPreferredUserId(String serverType, String serverName) {
|
||||
userIdPreferenceKey =
|
||||
"UserID_" + sanitizeString(serverType) + "_" + sanitizeString(serverName);
|
||||
userIdPreferenceKey = getPreferredUserIdPreferenceKey(serverType, serverName);
|
||||
return Preferences.getProperty(userIdPreferenceKey, defaultUserId);
|
||||
}
|
||||
|
||||
@@ -278,14 +296,6 @@ public class PasswordDialog extends DialogComponentProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private String sanitizeString(String str) {
|
||||
if (str == null) {
|
||||
return "_";
|
||||
}
|
||||
String newStr = str.replaceAll("[^a-zA-Z0-9_-]", "");
|
||||
return newStr.length() == 0 ? "_" : newStr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display error status
|
||||
* @param text the text
|
||||
|
||||
Reference in New Issue
Block a user