52
52
import com .amazonaws .mobile .auth .core .internal .util .ViewHelper ;
53
53
54
54
import org .json .JSONException ;
55
+ import org .json .JSONObject ;
55
56
56
57
import java .util .HashSet ;
57
58
import java .util .Set ;
62
63
import static com .amazonaws .mobile .auth .userpools .CognitoUserPoolsSignInProvider .AttributeKeys .USERNAME ;
63
64
import static com .amazonaws .mobile .auth .userpools .CognitoUserPoolsSignInProvider .AttributeKeys .VERIFICATION_CODE ;
64
65
66
+ import androidx .annotation .NonNull ;
67
+ import androidx .annotation .Nullable ;
68
+
65
69
/**
66
70
* Manages sign-in using Cognito User Pools.
67
71
*/
@@ -408,10 +412,14 @@ public void handleActivityResult(final int requestCode,
408
412
password = data .getStringExtra (PASSWORD );
409
413
verificationCode = data .getStringExtra (VERIFICATION_CODE );
410
414
411
- if (password .length () < PASSWORD_MIN_LENGTH ) {
415
+ Integer minimumPasswordLength = getMinimumPasswordLength (awsConfiguration );
416
+ if (minimumPasswordLength != null && password .length () < minimumPasswordLength ) {
412
417
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
+ ));
415
423
return ;
416
424
}
417
425
@@ -444,7 +452,7 @@ public void handleActivityResult(final int requestCode,
444
452
445
453
if (verificationCode .length () < 1 ) {
446
454
ViewHelper .showDialog (activity , activity .getString (R .string .title_activity_mfa ),
447
- activity .getString (R .string .mfa_failed )
455
+ activity .getString (R .string .mfa_failed )
448
456
+ " " + activity .getString (R .string .mfa_code_empty ));
449
457
return ;
450
458
}
@@ -469,7 +477,7 @@ public void handleActivityResult(final int requestCode,
469
477
470
478
if (verificationCode .length () < 1 ) {
471
479
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 )
473
481
+ " " + activity .getString (R .string .sign_up_confirm_code_missing ));
474
482
return ;
475
483
}
@@ -697,4 +705,13 @@ static int getBackgroundColor() {
697
705
static String getFontFamily () {
698
706
return fontFamily ;
699
707
}
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
+ }
700
717
}
0 commit comments