From 3409399ef1c4feb6370d830f6679fedc8f6256ec Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Mon, 25 Jul 2016 15:57:47 +0200 Subject: [PATCH] display specific error message when password is too weak on registration --- .../siacs/conversations/entities/Account.java | 9 ++++-- .../conversations/xmpp/XmppConnection.java | 29 +++++++++++-------- src/main/res/values/strings.xml | 1 + 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Account.java b/src/main/java/eu/siacs/conversations/entities/Account.java index 6c5fdd21b..7085c7ba9 100644 --- a/src/main/java/eu/siacs/conversations/entities/Account.java +++ b/src/main/java/eu/siacs/conversations/entities/Account.java @@ -110,7 +110,8 @@ public class Account extends AbstractEntity { HOST_UNKNOWN(true), REGISTRATION_PLEASE_WAIT(true), STREAM_ERROR(true), - POLICY_VIOLATION(true); + POLICY_VIOLATION(true), + REGISTRATION_PASSWORD_TOO_WEAK(true); private final boolean isError; @@ -118,11 +119,11 @@ public class Account extends AbstractEntity { return this.isError; } - private State(final boolean isError) { + State(final boolean isError) { this.isError = isError; } - private State() { + State() { this(false); } @@ -164,6 +165,8 @@ public class Account extends AbstractEntity { return R.string.account_status_policy_violation; case REGISTRATION_PLEASE_WAIT: return R.string.registration_please_wait; + case REGISTRATION_PASSWORD_TOO_WEAK: + return R.string.registration_password_too_weak; case STREAM_ERROR: return R.string.account_status_stream_error; default: diff --git a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java index ba1482fe3..6ed9f9d3b 100644 --- a/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java +++ b/src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java @@ -34,6 +34,7 @@ import java.security.Principal; import java.security.PrivateKey; import java.security.cert.X509Certificate; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; @@ -182,20 +183,24 @@ public class XmppConnection implements Runnable { forceCloseSocket(); changeStatus(Account.State.REGISTRATION_SUCCESSFUL); } else { + final List PASSWORD_TOO_WEAK_MSGS = Arrays.asList( + "The password is too weak", + "Please use a longer password."); Element error = packet.findChild("error"); - if (error != null && error.hasChild("conflict")) { - forceCloseSocket(); - changeStatus(Account.State.REGISTRATION_CONFLICT); - } else if (error != null - && "wait".equals(error.getAttribute("type")) - && error.hasChild("resource-constraint")) { - forceCloseSocket(); - changeStatus(Account.State.REGISTRATION_PLEASE_WAIT); - } else { - forceCloseSocket(); - changeStatus(Account.State.REGISTRATION_FAILED); - Log.d(Config.LOGTAG, packet.toString()); + Account.State state = Account.State.REGISTRATION_FAILED; + if (error != null) { + if (error.hasChild("conflict")) { + state = Account.State.REGISTRATION_CONFLICT; + } else if (error.hasChild("resource-constraint") + && "wait".equals(error.getAttribute("type"))) { + state = Account.State.REGISTRATION_PLEASE_WAIT; + } else if (error.hasChild("not-acceptable") + && PASSWORD_TOO_WEAK_MSGS.contains(error.findChildContent("text"))) { + state = Account.State.REGISTRATION_PASSWORD_TOO_WEAK; + } } + changeStatus(state); + forceCloseSocket(); } } }; diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 84d9fee2b..9b404295a 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -648,6 +648,7 @@ Your device does not support opting out of battery optimization Show password Registration failed: Try again later + Registration failed: Password too weak Create conference Join or create conference Subject