Merge pull request #3239 from archibishop/username-validation-gpodder-login

Validate username for characters not accepted.
This commit is contained in:
H. Lehmann 2019-06-26 06:51:42 +02:00 committed by GitHub
commit abcd6f772e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -25,6 +25,8 @@ import android.widget.ViewFlipper;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import de.danoeh.antennapod.BuildConfig;
import de.danoeh.antennapod.R;
@ -123,6 +125,11 @@ public class GpodnetAuthenticationActivity extends AppCompatActivity {
final String usernameStr = username.getText().toString();
final String passwordStr = password.getText().toString();
if (usernameHasUnwantedChars(usernameStr)) {
txtvError.setText(R.string.gpodnetsync_username_characters_error);
txtvError.setVisibility(View.VISIBLE);
return;
}
if (BuildConfig.DEBUG) Log.d(TAG, "Checking login credentials");
AsyncTask<GpodnetService, Void, Void> authTask = new AsyncTask<GpodnetService, Void, Void>() {
@ -395,4 +402,10 @@ public class GpodnetAuthenticationActivity extends AppCompatActivity {
finish();
}
}
private boolean usernameHasUnwantedChars(String username) {
Pattern special = Pattern.compile("[!@#$%&*()+=|<>?{}\\[\\]~]");
Matcher containsUnwantedChars = special.matcher(username);
return containsUnwantedChars.find();
}
}

View File

@ -642,6 +642,7 @@
<string name="gpodnetsync_error_descr">An error occurred during syncing:\u0020</string>
<string name="gpodnetsync_pref_report_successful">Successful</string>
<string name="gpodnetsync_pref_report_failed">Failed</string>
<string name="gpodnetsync_username_characters_error">Usernames may only contain letters, digits, hyphens and underscores.</string>
<!-- Directory chooser -->
<string name="selected_folder_label">Selected folder:</string>