5252import com .amazonaws .mobile .auth .core .internal .util .ViewHelper ;
5353
5454import org .json .JSONException ;
55+ import org .json .JSONObject ;
5556
5657import java .util .HashSet ;
5758import java .util .Set ;
6263import static com .amazonaws .mobile .auth .userpools .CognitoUserPoolsSignInProvider .AttributeKeys .USERNAME ;
6364import static com .amazonaws .mobile .auth .userpools .CognitoUserPoolsSignInProvider .AttributeKeys .VERIFICATION_CODE ;
6465
66+ import androidx .annotation .NonNull ;
67+ import androidx .annotation .Nullable ;
68+
6569/**
6670 * Manages sign-in using Cognito User Pools.
6771 */
@@ -408,10 +412,14 @@ public void handleActivityResult(final int requestCode,
408412 password = data .getStringExtra (PASSWORD );
409413 verificationCode = data .getStringExtra (VERIFICATION_CODE );
410414
411- if (password .length () < PASSWORD_MIN_LENGTH ) {
415+ Integer minimumPasswordLength = getMinimumPasswordLength (awsConfiguration );
416+ if (minimumPasswordLength != null && password .length () < minimumPasswordLength ) {
412417 ViewHelper .showDialog (activity , activity .getString (R .string .title_activity_forgot_password ),
413- activity .getString (R .string .password_change_failed )
414- + " " + activity .getString (R .string .password_length_validation_failed ));
418+ activity .getString (R .string .password_change_failed )
419+ + " " + activity .getString (
420+ R .string .password_length_validation_failed_variable ,
421+ minimumPasswordLength
422+ ));
415423 return ;
416424 }
417425
@@ -444,7 +452,7 @@ public void handleActivityResult(final int requestCode,
444452
445453 if (verificationCode .length () < 1 ) {
446454 ViewHelper .showDialog (activity , activity .getString (R .string .title_activity_mfa ),
447- activity .getString (R .string .mfa_failed )
455+ activity .getString (R .string .mfa_failed )
448456 + " " + activity .getString (R .string .mfa_code_empty ));
449457 return ;
450458 }
@@ -469,7 +477,7 @@ public void handleActivityResult(final int requestCode,
469477
470478 if (verificationCode .length () < 1 ) {
471479 ViewHelper .showDialog (activity , activity .getString (R .string .title_activity_sign_up_confirm ),
472- activity .getString (R .string .sign_up_confirm_title )
480+ activity .getString (R .string .sign_up_confirm_title )
473481 + " " + activity .getString (R .string .sign_up_confirm_code_missing ));
474482 return ;
475483 }
@@ -697,4 +705,13 @@ static int getBackgroundColor() {
697705 static String getFontFamily () {
698706 return fontFamily ;
699707 }
708+
709+ @ Nullable
710+ static Integer getMinimumPasswordLength (@ NonNull final AWSConfiguration configuration ) {
711+ JSONObject auth = configuration .optJsonObject ("Auth" );
712+ if (auth == null ) return null ;
713+ JSONObject passwordSettings = auth .optJSONObject ("passwordProtectionSettings" );
714+ if (passwordSettings == null ) return null ;
715+ return passwordSettings .optInt ("passwordPolicyMinLength" );
716+ }
700717}
0 commit comments