mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 20:15:21 +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.util.Set;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
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) {}
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
Pattern pattern = Pattern.compile("[a-zA-Z0-9_]+");
|
||||
Matcher matcher = pattern.matcher(s.toString());
|
||||
if (s.toString().isEmpty()) {
|
||||
name.getInput().setError("Invalid");
|
||||
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) {
|
||||
name.getInput().setError(getString(R.string.CreateProfileActivity_too_long));
|
||||
finishButton.setEnabled(false);
|
||||
|
@ -27,6 +27,9 @@ class DisplayNameActivity : BaseActionBarActivity() {
|
||||
if (name.isEmpty()) {
|
||||
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) {
|
||||
return nameEditText.input.setError("Too Long")
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user