Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static int minimumNumber(int n, String password) {
- // Return the minimum number of characters to make the password strong
- char[] pw = password.toCharArray();
- int specialCharacters =0;
- int numbers =0;
- int lowerCase =0;
- int upperCase =0;
- String special_characters = "!@#$%^&*()-+";
- for(int i=0;i<n;i++){
- if((int)pw[i]>=48 && (int)pw[i]<=57)
- numbers++;
- else if((int)pw[i]>=65 && (int)pw[i]<=90)
- upperCase++;
- else if((int)pw[i]>=97 && (int)pw[i]<=122)
- lowerCase++;
- else if(special_characters.contains(""+pw[i]))
- specialCharacters++;
- if(numbers>=1 && upperCase >=1 && lowerCase>=1 && pw.length>=6 && specialCharacters>=1){
- return 0;
- }
- }
- if(n >=6){
- int count =0;
- if(numbers==0)
- count++;
- if(upperCase==0)
- count++;
- if(lowerCase==0)
- count++;
- if(specialCharacters==0)
- count++;
- return count;
- }else{
- int count =0;
- if(numbers==0)
- count++;
- if(upperCase==0)
- count++;
- if(lowerCase==0)
- count++;
- if(specialCharacters==0)
- count++;
- int ans = count+n;
- if(ans>=6)
- return count;
- return 6-pw.length;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement