Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Parse then analyze with an array?

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Parse then analyze with an array?

    I am making a password strength rater for fun and I am just missing one part of the equation. I'm trying to find a way to add value to my C variable so that if has an upper case letter it adds 26, another 26 if the string has a lower case, if the string has any number add 10, and special characters 15. I know I have to parse the string but the only way I could think of is by scanning each letter using an array. I think I read that some where before but I'm sure there is a much more efficient way. An article pointing me the right direction or some hints would be great. Thanks!

    package sandbox;
     
    import javax.swing.JOptionPane;
     
    class Strength {
     
    	public static void main(String[] args){
    		String password =JOptionPane.showInputDialog("Enter your password here:");
    		//parse password to turn set c and n value;
    		int c;
    		int n = password.length();
    		double pStrength = Math.pow(c,n);
     
    		if (pStrength >= 5000){
    			System.out.println("You have a strong password!");
    			}
    			else System.out.println("Try harder");
    		}
     
    	}
    Last edited by 0ffConstantly; October 26th, 2012 at 10:33 PM. Reason: making more concise


  2. #2
    Junior Member
    Join Date
    Oct 2012
    Posts
    9
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Re: Parse then analyze with an array?

    Okay after hours of scouring google and stackoverflow I kind of have a solution. It doesn't look very pretty and it feels like I put it together using duck tape but here is what I got. I'm studying for my Security+ certification right now so that's where I got the C^N formula from.

    package sandbox;
     
    import javax.swing.JOptionPane;
    import java.util.regex.*;
     
    class Strength {
     
    	public static void main(String[] args){
    	String password =JOptionPane.showInputDialog("Enter your password here:");
    		//parse password to turn set c and n value;
    		int c = 0;
     
    		 //let's figure things out
    		 int uppercase = 0, lowercase = 0, numbers = 0, specChars = 0;
    		 for (int i=0; i<password.length(); i++){
    			 if(Character.isUpperCase(password.charAt(i))) uppercase++;
    			 else if (Character.isLowerCase(password.charAt(i))) lowercase++;
    		 }
    		 Pattern p = Pattern.compile("^a-zA-Z0-9");
    		 Matcher m = p.matcher(password);
    		 boolean b = m.matches();
    		 if (b == false){
    			 specChars = specChars +1;
    		 }
    		 if(password.matches(".*[0-9]*.")){
    			 numbers++;
    		 }
    		 //Let's add!
    		 if(uppercase> 0){
    			 c = c + 26;
    		 }
    		 if(lowercase> 0){
    			 c = c + 26;
    		 }
    		 if(numbers>0){
    			 c = c + 10;
    		 }
    		 if(specChars>0){
    			 c = c + 10;
    		 }
    		int n = password.length();
    		double pStrength = Math.pow(c,n);
     
    		System.out.println("C ="+ c);
    		System.out.println("N ="+ n);
    		System.out.println("C^N ="+ pStrength);
     
    		if (pStrength >= Math.pow(72,12)){
    			System.out.println("Your password is strong enough to store DoD files.");
    		}
    		else if (pStrength <= Math.pow(72,12)){
    			System.out.println("Your password is NOT strong enough to store DoD files.");
    	}
     
    }
    	}

Similar Threads

  1. Please help me analyze this java core dump on AIX
    By acejun01 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 12th, 2014, 05:21 AM
  2. How to parse an XML having same tag.
    By 1bun100 in forum File I/O & Other I/O Streams
    Replies: 12
    Last Post: February 24th, 2012, 08:34 AM
  3. HOW TO PARSE A TEXT FILE
    By hervebags in forum Algorithms & Recursion
    Replies: 4
    Last Post: June 1st, 2011, 09:36 AM
  4. how to parse this string to date ?
    By vaibhav in forum Member Introductions
    Replies: 1
    Last Post: March 11th, 2011, 04:17 PM
  5. Can anyone help analyze these java dumps for Windows ?
    By ansonxiaoshun in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 16th, 2011, 01:27 AM