I have an exercise about the analysis of passwords (weak vs strong) and I have to create 2 constructors. One of them must receive the length of a password and the password must be created randomly, how can I do that ?
Also I'm having trouble determining if the password is weak or strong. It's going to be strong if the password has at least 3 uppercase letters, 2 lowercase letters and 6 numbers.
class Password { private double length; private String password; Password()//default constructor with password length 8 { password="defaultt"; length=8; } Password(double length) { this.length=length; password="";//generate a random password, how? } boolean isStrong(String password) { int totalnumbers=0; int upper=0; int lower=0; for(int i=0;i<password.length;i++)//marks an error in .length why? { if (password.charAt(i)>='0' && password.charAt(i)<='9') totalnumbers+=1; if (password.charAt(i) is lowercase)//what can I do here? lower+=1; if (password.charAt(i) is uppercase) upper+=1; } if(totalnumbers>=6 && lower>=2 && upper>=3) return true; else return false; } generatePassword(double length) { password;//generate the password of the object with this.length //how to do it? } String getPassword() { return password; } double getLength() { return length; } void setLength(double length) { this.length=length; } } public class Exercises2 { public static void main(String[] args) { Password x=new Password(); Password array[]; Scanner rd=new Scanner(System.in); int Size; System.out.println("Give the size of the passwords array "); Size=rd.nextInt(); array=new Password[Size]; for( int i=0;i<Size;i++) { array[i]=new Password();//creation of an object for each position of the array } for(int j=0;j<Size;j++) { System.out.println("Give the size for each password of the array "); array[j]=[rd.nextInt]; //length for each password of the array } Password arrayBooleans[]=new Password[Size]; for (int k=0;k<Size;k++){ arrayBooleans[k]=x.isStrong(array[k]); } for(int i=0;i<Size;i++) { System.out.println("password "+i+ arrayBooleans[i]); } } }