mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 17:58:25 +00:00
Limit allowed characters in display names
This commit is contained in:
parent
f7e01688b0
commit
6d0858cf35
@ -67,6 +67,8 @@ import java.io.IOException;
|
|||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@ -227,9 +229,14 @@ public class CreateProfileActivity extends BaseActionBarActivity implements Inje
|
|||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||||
@Override
|
@Override
|
||||||
public void afterTextChanged(Editable s) {
|
public void afterTextChanged(Editable s) {
|
||||||
|
Pattern pattern = Pattern.compile("[a-zA-Z0-9_]+");
|
||||||
|
Matcher matcher = pattern.matcher(s.toString());
|
||||||
if (s.toString().isEmpty()) {
|
if (s.toString().isEmpty()) {
|
||||||
name.getInput().setError("Invalid");
|
name.getInput().setError("Invalid");
|
||||||
finishButton.setEnabled(false);
|
finishButton.setEnabled(false);
|
||||||
|
} else if (!matcher.matches()) {
|
||||||
|
name.getInput().setError("Invalid (a-z, A-Z, 0-9 and _ only)");
|
||||||
|
finishButton.setEnabled(false);
|
||||||
} else if (s.toString().getBytes().length > ProfileCipher.NAME_PADDED_LENGTH) {
|
} else if (s.toString().getBytes().length > ProfileCipher.NAME_PADDED_LENGTH) {
|
||||||
name.getInput().setError(getString(R.string.CreateProfileActivity_too_long));
|
name.getInput().setError(getString(R.string.CreateProfileActivity_too_long));
|
||||||
finishButton.setEnabled(false);
|
finishButton.setEnabled(false);
|
||||||
|
@ -27,6 +27,9 @@ class DisplayNameActivity : BaseActionBarActivity() {
|
|||||||
if (name.isEmpty()) {
|
if (name.isEmpty()) {
|
||||||
return nameEditText.input.setError("Invalid")
|
return nameEditText.input.setError("Invalid")
|
||||||
}
|
}
|
||||||
|
if (!name.matches(Regex("[a-zA-Z0-9_]+"))) {
|
||||||
|
return nameEditText.input.setError("Invalid (a-z, A-Z, 0-9 and _ only)")
|
||||||
|
}
|
||||||
if (name.toByteArray().size > ProfileCipher.NAME_PADDED_LENGTH) {
|
if (name.toByteArray().size > ProfileCipher.NAME_PADDED_LENGTH) {
|
||||||
return nameEditText.input.setError("Too Long")
|
return nameEditText.input.setError("Too Long")
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user