aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2016-07-25 15:57:47 +0200
committerChristian Schneppe <christian@pix-art.de>2016-07-25 19:50:40 +0200
commit5cf5195e266b60bd3721116d012c463b681c62f5 (patch)
tree7c0e9ed5e09e47de438bf06a80f77d4acc8d2248
parente388c64361a3dad44442dd1f8633e452302188e8 (diff)
display specific error message when password is too weak on registration
-rw-r--r--src/main/java/eu/siacs/conversations/entities/Account.java9
-rw-r--r--src/main/java/eu/siacs/conversations/xmpp/XmppConnection.java29
-rw-r--r--src/main/res/values/strings.xml1
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 2f2ffc049..c7359829c 100644
--- a/src/main/java/eu/siacs/conversations/entities/Account.java
+++ b/src/main/java/eu/siacs/conversations/entities/Account.java
@@ -109,7 +109,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;
@@ -117,11 +118,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);
}
@@ -163,6 +164,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 a4476c052..fec96969b 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;
@@ -183,20 +184,24 @@ public class XmppConnection implements Runnable {
forceCloseSocket();
changeStatus(Account.State.REGISTRATION_SUCCESSFUL);
} else {
+ final List<String> 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 0cffa2f4d..3528dcc9e 100644
--- a/src/main/res/values/strings.xml
+++ b/src/main/res/values/strings.xml
@@ -645,6 +645,7 @@
<string name="leave_conference_warning">Do you really want to leave this conference? You will no longer be notified of new messages until joining the conference again.</string>
<string name="show_password">Show password</string>
<string name="registration_please_wait">Registration failed: Try again later</string>
+ <string name="registration_password_too_weak">Registration failed: Password too weak</string>
<string name="create_conference">Create conference</string>
<string name="join_or_create_conference">Join or create conference</string>
<string name="conference_subject">Subject</string>