Android Password Constraint rule example one

Source: Internet
Author: User

A common password rule for Android

(a) The password must be 8 to 16 digits;
(b) The password must contain English letters and numbers;
(c) The password cannot contain 4 consecutive characters of the same character, such as 0000 or AAAA;
(d) The password must not contain 4 consecutive increments or successive decreasing numbers or letters, such as 1234 or ABCD.

Package Test;import Java.util.arraylist;import Java.util.list;import java.util.regex.matcher;import Java.util.regex.pattern;public class Test {private static Boolean isfourdigtialdec (String str) {if (str = = NULL | | str = = "" ) {return true;} String regex= "(? <=\\d|^) (?:(? : 9 (? =8|\\d))? (?: 8 (? =7|\\d))? (?: 7 (? =6|\\d))? (?: 6 (? =5|\\d))? (?: 5 (? =4|\\d))? (?: 4 (? =3|\\d))? (?: 3 (? =2|\\d))? (?: 2 (? =1|\\d))? (?: 1 (? =0|\\d))? (?: 0 (? =\\d|$))?) (? =\\d|$) "; String regex= "^\\d (?:(? <=1) 0| (? <=2) 1| (? <=3) 2| (? <=4) 3| (? <=5) 4| (? <=6) 5| (? <=7) 6| (? <=8) 7| (? <=9) 8) {3}$ ";        Pattern p = pattern.compile (regEx);  Matcher m = p.matcher (str); if (M.find ()) {return true;} return false;} private static Boolean isfourdigtialadd (String str) {if (str = = NULL | | str = = "") {return true;} String regex= "^\\d (?:(? <=0) 1| (? <=1) 2| (? <=2) 3| (? <=3) 4| (? <=4) 5| (? <=5) 6| (? <=6) 7|     (? <=7) 8| (? <=8) 9) {3}$ ";        Pattern p = pattern.compile (regEx);  Matcher m = p.matcher (str); if (M.find ()) {return true;} return false;} private static Boolean isalldigtial (String str) {if (str = = NULL | | str = = "") {return true;}     String regex= "^[0-9]{6,18}$";        Pattern p = pattern.compile (regEx);  Matcher m = p.matcher (str); if (M.find ()) {return true;} return false;} private static Boolean isallletter (String str) {if (str = = NULL | | str = = "") {return true;}     String regex= "^[a-za-z]{6,18}$";        Pattern p = pattern.compile (regEx);  Matcher m = p.matcher (str); if (M.find ()) {return true;} return false;} private static Boolean isfourdigtial (String str) {if (str = = NULL | | str = = "") {return true;}     String regex= "^[0-9]{4,4}$";        Pattern p = pattern.compile (regEx);  Matcher m = p.matcher (str); if (M.find ()) {return true;} return false;} private static Boolean isfourletter (String str) {if (str = = NULL | | str = = "") {return true;}     String regex= "^[a-za-z]{4,4}$";        Pattern p = pattern.compile (regEx); Matcher m = P.matCher (str); if (M.find ()) {return true;} return false;} public static Boolean isdgcheckukeypinpwd (String str) {if (str = = NULL | | str = = "") {return true;} if (isalldigtial (str)) {return true;} if (Isallletter (str)) {return true;} System.out.println (str); list<string> arr2 =new arraylist<string> (); int i=0;int len=str.length ();//system.out.println (len); while (i<len-3) {Arr2.add (str.substring (i, i+4));//system.err.println (arr2.tostring ()); i++;} int J=0;while (J<arr2.size ()) {if (Isfourdigtial (Arr2.get (j))) {if (Arr2.get (j). CharAt (0) ==arr2.get (j). CharAt (1) ) && (Arr2.get (j). CharAt (1) ==arr2.get (j). CharAt (2)) && (Arr2.get (j). CharAt (2) ==arr2.get (j). CharAt (  3)) {return false; }if (Isfourdigtialadd (Arr2.get (j))) {return false;} if (Isfourdigtialdec (Arr2.get (j))) {return false;}} if (Isfourletter (Arr2.get (j))) {if (Arr2.get (j). CharAt (0) ==arr2.get (j). CharAt (1)) && (Arr2.get (j). CharAt (1  ) ==arr2.get (j). CharAt (2)) && (Arr2.get (j). CharAt (2) ==arr2.get (j). CharAt (3))) {return false; }char[] Arrpwd = new Char[arr2.get (j). Length ()];for (int k = 3; k >= 0; k--) {Arrpwd[k]=arr2.get (j). CharAt (k);} System.out.println (ARRPWD);//increment or decrement if ((arrpwd[3]-arrpwd[2]==1) && (arrpwd[2]-arrpwd[1]==1) && ( arrpwd[1]-arrpwd[0]==1)) | | ((arrpwd[3]-arrpwd[2]==-1) && (arrpwd[2]-arrpwd[1]==-1) && (arrpwd[1]-arrpwd[0]==-1)))    {return false; }}j++;} return true;} public static void Main (string[] args) {System.err.println (Isdgcheckukeypinpwd ("ABCE1236ABCE"));// System.err.println (Isfourdigtialadd ("12345"))//system.err.println (Isfourdigtialdec ("5432"));}}

  

Android Password Constraint rule example one

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.