Skip to content

Commit ca29a2d

Browse files
daniel-becktimja
andauthored
Friendlier error message when the password is too long (#10626)
* Friendlier error message when the password is too long * Remove CTA Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com> * Remove "yours" --------- Co-authored-by: Daniel Beck <daniel-beck@users.noreply.github.com> Co-authored-by: Tim Jacomb <21194782+timja@users.noreply.github.com>
1 parent 4000cd9 commit ca29a2d

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

core/src/main/java/hudson/security/HudsonPrivateSecurityRealm.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,9 @@ public String encode(CharSequence rawPassword) {
939939
return super.encode(rawPassword);
940940
} catch (IllegalArgumentException ex) {
941941
if (ex.getMessage().equals("password cannot be more than 72 bytes")) {
942+
if (rawPassword.toString().matches("\\A\\p{ASCII}+\\z")) {
943+
throw new IllegalArgumentException(Messages.HudsonPrivateSecurityRealm_CreateAccount_BCrypt_PasswordTooLong_ASCII());
944+
}
942945
throw new IllegalArgumentException(Messages.HudsonPrivateSecurityRealm_CreateAccount_BCrypt_PasswordTooLong());
943946
}
944947
throw ex;

core/src/main/resources/hudson/security/Messages.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ HudsonPrivateSecurityRealm.ManageUserLinks.Description=Create/delete/modify user
3737
HudsonPrivateSecurityRealm.CreateAccount.TextNotMatchWordInImage=Text didn''t match the word shown in the image
3838
HudsonPrivateSecurityRealm.CreateAccount.PasswordNotMatch=Password didn''t match
3939
HudsonPrivateSecurityRealm.CreateAccount.FIPS.PasswordLengthInvalid=Password must be at least 14 characters long
40-
HudsonPrivateSecurityRealm.CreateAccount.BCrypt.PasswordTooLong=Jenkins’ own user database currently only supports passwords of up to 72 bytes UTF-8 (72 basic ASCII characters, 24-36 CJK characters, or 18 emoji). Please use a shorter password.
40+
HudsonPrivateSecurityRealm.CreateAccount.BCrypt.PasswordTooLong.ASCII=Password cannot be longer than 72 characters.
41+
HudsonPrivateSecurityRealm.CreateAccount.BCrypt.PasswordTooLong=Password cannot be longer than 72 characters (a-z, A-Z, 0-9, and basic punctuation; fewer when using other characters, like Chinese characters or emoji).
4142
HudsonPrivateSecurityRealm.CreateAccount.PasswordRequired=Password is required
4243
HudsonPrivateSecurityRealm.CreateAccount.UserNameRequired=User name is required
4344
HudsonPrivateSecurityRealm.CreateAccount.UserNameInvalidCharacters=User name must only contain alphanumeric characters, underscore and dash

core/src/test/java/hudson/security/HudsonPrivateSecurityRealmTest.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,16 @@ public void testJBCryptPasswordMatching() {
157157
}
158158

159159
@Issue("JENKINS-75533")
160-
public void ensureExpectedMessage() {
160+
public void ensureExpectedMessageAscii() {
161161
final IllegalArgumentException ex = Assert.assertThrows(IllegalArgumentException.class, () -> HudsonPrivateSecurityRealm.PASSWORD_HASH_ENCODER.encode("1234567890123456789012345678901234567890123456789012345678901234567890123"));
162+
assertThat(ex.getMessage(), is(Messages.HudsonPrivateSecurityRealm_CreateAccount_BCrypt_PasswordTooLong_ASCII()));
163+
}
164+
165+
@Issue("JENKINS-75533")
166+
public void ensureExpectedMessageEmoji() {
167+
final IllegalArgumentException ex = Assert.assertThrows(IllegalArgumentException.class, () -> HudsonPrivateSecurityRealm.PASSWORD_HASH_ENCODER.encode(
168+
"\uD83E\uDD20\uD83E\uDD20\uD83E\uDD20\uD83E\uDD20\uD83E\uDD20\uD83E\uDD20\uD83E\uDD20\uD83E\uDD20\uD83E\uDD20" +
169+
"\uD83E\uDD20\uD83E\uDD20\uD83E\uDD20\uD83E\uDD20\uD83E\uDD20\uD83E\uDD20\uD83E\uDD20\uD83E\uDD20\uD83E\uDD20\uD83E\uDD20")); // 🤠
162170
assertThat(ex.getMessage(), is(Messages.HudsonPrivateSecurityRealm_CreateAccount_BCrypt_PasswordTooLong()));
163171
}
164172
}

0 commit comments

Comments
 (0)