Take 2

If you’re going to create your own login policy you might want to make sure that passwords are a certain length, so in the second example (see Listing 3-4) we’re going to add a minimum password length of six. The code to check the length is straightforward (see line 95). I’ve also added a method, invalidEmail, to make sure that the email address is valid using the following regular expression (see line 78).

String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";

From personal experience I should point out that if you’re writing a method to check emails, or indeed any other authentication, then you should always make the default return what you would expect ...

Get Bulletproof Android™: Practical Advice for Building Secure Apps now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.