Skip to content

Commit 3411eeb

Browse files
committed
1. Updated validator class.
1 parent f42fb24 commit 3411eeb

File tree

1 file changed

+83
-3
lines changed

1 file changed

+83
-3
lines changed

app/src/main/java/com/amit/utilities/Validator.java

Lines changed: 83 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.amit.utilities;
22

3+
import android.provider.UserDictionary;
34
import android.util.Log;
45

56
import java.util.regex.Matcher;
@@ -15,6 +16,8 @@
1516

1617
public class Validator
1718
{
19+
private UserDictionary userDictionary;
20+
1821
private static final String TAG = Validator.class.getSimpleName();
1922

2023
/**
@@ -123,7 +126,7 @@ public static boolean onlyCharacters(String string)
123126
{
124127
try
125128
{
126-
return string.matches(".*\\d.*");
129+
return string.matches("^[A-Za-z]+$");
127130
}
128131
catch (Exception e)
129132
{
@@ -146,7 +149,7 @@ public static boolean atLeastOneLowerCase(String string)
146149
{
147150
try
148151
{
149-
return string.matches("[a-z0-9]+");
152+
return !string.equals(string.toUpperCase());
150153
}
151154
catch (Exception e)
152155
{
@@ -169,7 +172,7 @@ public static boolean atLeastOneUpperCase(String string)
169172
{
170173
try
171174
{
172-
return string.matches("[A-Z0-9]+");
175+
return !string.equals(string.toLowerCase());
173176
}
174177
catch (Exception e)
175178
{
@@ -291,4 +294,81 @@ public static boolean atLeastOneSpecialCharacters(String string)
291294
return false;
292295
}
293296
}
297+
298+
/**
299+
* is valid password
300+
* this method will check if the password is valid for the following conditions:
301+
*
302+
* 1. It should of minimum 8 in length.
303+
* 2. It should have at least one upper case.
304+
* 3. It should have at least one lower case.
305+
* 4. It should have at least one special character.
306+
* 5. It should have at least one numeric value.
307+
*
308+
* @return true or false.
309+
**/
310+
private static boolean isValidPassword(String password)
311+
{
312+
final String PASSWORD_PATTERN = "^(?=.*[0-9])(?=.*[A-Z])(?=.*[@#$%^&+=!])(?=\\S+$).{4,}$";
313+
Pattern pattern = Pattern.compile(PASSWORD_PATTERN);
314+
Matcher matcher = pattern.matcher(password);
315+
return matcher.matches();
316+
}
317+
318+
/**
319+
* password strength method
320+
* this method determines the strength of the string entered.
321+
*
322+
* @return int value with strength of the password.
323+
**/
324+
private int passwordStrength(String password)
325+
{
326+
int strength = 0;
327+
328+
if (atLeastOneUpperCase(password))
329+
{
330+
strength += 15;
331+
}
332+
333+
if (atLeastOneUpperCase(password))
334+
{
335+
strength += 15;
336+
}
337+
338+
if (atLeastOneSpecialCharacters(password))
339+
{
340+
strength += 20;
341+
}
342+
343+
if (atLeastOneNumber(password))
344+
{
345+
strength += 20;
346+
}
347+
348+
if (password.length() >= 8)
349+
{
350+
strength += 10;
351+
}
352+
353+
if (password.length() > 15)
354+
{
355+
strength += 20;
356+
}
357+
358+
return strength;
359+
}
360+
361+
private boolean spellCheck(String string)
362+
{
363+
try
364+
{
365+
return UserDictionary.Words.WORD.contains(string);
366+
}
367+
catch (Exception e)
368+
{
369+
Log.e(TAG, "spellCheck: exception while checking for spelling.");
370+
e.printStackTrace();
371+
return false;
372+
}
373+
}
294374
}

0 commit comments

Comments
 (0)