Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Password strength checker in Android [closed]

Tags:

android

How can we implement a password strength checker in Android?

like image 220
MorningGlory Avatar asked Feb 03 '23 20:02

MorningGlory


1 Answers

This seems to work:

//ASSERT password not null
    private float getRating(String password) throws IllegalArgumentException {
        if (password == null) {throw new IllegalArgumentException();}
        int passwordStrength = 0;    
        if (password.length() > 5) {passwordStrength++;} // minimal pw length of 6
        if (password.toLowerCase()!= password) {passwordStrength++;} // lower and upper case
        if (password.length() > 8) {passwordStrength++;} // good pw length of 9+
        int numDigits= Utilities.getNumberDigits(password);
        if (numDigits > 0 && numDigits != password.length()) {passwordStrength++;} // contains digits and non-digits
        return (float)passwordStrength;
}     

Utilities class

public static int getNumberDigits(String inString){
          if (isEmpty(inString)) {
              return 0;
          }
          int numDigits= 0;
          int length= inString.length();
          for (int i = 0; i < length; i++) {
              if (Character.isDigit(inString.charAt(i))) {
                  numDigits++; 
              }
          }
          return numDigits; 
      }

  public static boolean isEmpty(String inString) {
      return inString == null || inString.length() == 0;
  }
like image 200
JAL Avatar answered Feb 05 '23 10:02

JAL