Skip to content

Commit ff38cef

Browse files
authored
Merge pull request #5295 from microsoft/qianjin-s187-bugfix-01
bugfix: password validate not match with portal when the length of common sequence (not sub string) between username and password is larger than 3.
2 parents 6f16305 + 048f2d1 commit ff38cef

File tree

1 file changed

+22
-5
lines changed
  • PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/database

1 file changed

+22
-5
lines changed

PluginsAndFeatures/azure-toolkit-for-intellij/src/com/microsoft/azure/toolkit/intellij/database/PasswordUtils.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import com.microsoft.azure.toolkit.lib.common.form.AzureValidationInfo;
1111
import org.apache.commons.lang3.CharUtils;
1212
import org.apache.commons.lang3.StringUtils;
13-
import org.apache.commons.text.similarity.LongestCommonSubsequence;
1413

1514
import javax.swing.*;
1615
import java.util.Arrays;
@@ -73,11 +72,10 @@ private static AzureValidationInfo validatePassword(String password, String user
7372
.type(AzureValidationInfo.Type.ERROR).build();
7473
}
7574
// validate longest common subsequence between username and password.
76-
LongestCommonSubsequence algorithm = new LongestCommonSubsequence();
77-
int longestCommonSubsequenceLength = algorithm.apply(username, password);
75+
int longestCommonSubstringLength = longestCommonSubstringLength(username, password);
7876
int usernameLength = StringUtils.length(username);
79-
if ((usernameLength > 0 && longestCommonSubsequenceLength == usernameLength)
80-
|| longestCommonSubsequenceLength >= LONGEST_COMMON_SUBSEQUENCE_BETWEEN_NAME_AND_PASSWORD) {
77+
if ((usernameLength > 0 && longestCommonSubstringLength == usernameLength)
78+
|| longestCommonSubstringLength >= LONGEST_COMMON_SUBSEQUENCE_BETWEEN_NAME_AND_PASSWORD) {
8179
final AzureValidationInfo.AzureValidationInfoBuilder builder = AzureValidationInfo.builder();
8280
return builder.input(input).message("Your password cannot contain all or part of the login name." +
8381
" Part of a login name is defined as three or more consecutive alphanumeric characters.")
@@ -86,6 +84,25 @@ private static AzureValidationInfo validatePassword(String password, String user
8684
return AzureValidationInfo.OK;
8785
}
8886

87+
private static int longestCommonSubstringLength(String left, String right) {
88+
if (StringUtils.isAnyBlank(left, right)) {
89+
return 0;
90+
}
91+
int max = 0;
92+
final int[][] dp = new int[left.length() + 1][right.length() + 1];
93+
for (int i = 0; i < left.length(); i++) {
94+
for (int j = 0; j < right.length(); j++) {
95+
if (left.charAt(i) == right.charAt(j)) {
96+
dp[i + 1][j + 1] = dp[i][j] + 1;
97+
} else {
98+
dp[i + 1][j + 1] = 0;
99+
}
100+
max = Math.max(max, dp[i + 1][j + 1]);
101+
}
102+
}
103+
return max;
104+
}
105+
89106
private static int countCharacterCategories(final String value) {
90107
final Boolean[] categories = new Boolean[] {false, false, false, false};
91108
for (char ch : value.toCharArray()) {

0 commit comments

Comments
 (0)