开发者

Password strength checker in Android [closed]

开发者 https://www.devze.com 2023-02-14 07:37 出处:网络
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve thi开发者_如何学Pythons question? Update the question so it focuses on one problem on
Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve thi开发者_如何学Pythons question? Update the question so it focuses on one problem only by editing this post.

Closed 7 years ago.

Improve this question

How can we implement a password strength checker in Android?


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;
  }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号