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 3 of 3

Thread: Help with ArrayList Features

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    21
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy Help with ArrayList Features

    Iv created an array list which contains people and attributes such as user id, username etc. It works fine for the most part. It allows the user to enter a name into the system. If the name entered matches a name stored in the array list then it will display that user, its id, name and password. I need to implement a password strength checker; but i am struggling.

    First off; i need a method that will determine how strong a password is. I then need to find a means of how to output the result of this, outputting it alongside the other outputted attributes: id, name and password.

    I have of course attempted this, however being fairly new to Java my attempt did not go too well. I understand basic programming concepts; however when it comes to implementing ideas with code and syntax; my ideas fall flat.

    Here is what i have attempted so far, but to be honest its probably completely different to the exact strength check and way that i want the result to be displayed. Iv shown my code below. But please, anybody; im asking if you could offer me the solution that i am looking for. I know that the code below is a good start, but its not close to implementing the code in a way that the password strength result can be outputted in the arraylist after a search for a user and their password is made.

    private int checkPasswordStrength2(String passw) 
        {
                    int strengthCount=0;
            String[] partialRegexChecks = { ".*[a-z]+.*", // lower
                                            ".*[A-Z]+.*", // upper
                                            ".*[\\d]+.*", // digits
                                            ".*[@#$%]+.*" // symbols
            };
                        if (passw.matches(partialRegexChecks[0])) {
                        strengthCount+=1;
                }
                        if (passw.matches(partialRegexChecks[1])) {
                        strengthCount+=1;
                }
                        if (passw.matches(partialRegexChecks[2])) {
                        strengthCount+=1;
                }
                        if (passw.matches(partialRegexChecks[3])) {
                        strengthCount+=1;
                }
     
                if (strengthCount==1) {
                    System.out.println("Password is weak");
                }
     
                if (strengthCount==2) {
                    System.out.println("Password is meduim");
                }
     
                if (strengthCount==3) {
                    System.out.println("Password is good");
                }
     
                if (strengthCount==4) {
                    System.out.println("Password is very good");
                }
     
            return strengthCount;
        }

    Iv been at it for hours now, and i mean hours. I just really want to get this done. Iv looked for solutions online; but they implement a password strength checker much differently to how mine needs to work from what i can tell.


  2. #2
    Junior Member
    Join Date
    Jun 2014
    Posts
    2
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Help with ArrayList Features

    Your problem definition is not entirely clear as you have not stated your criteria of what is good and bad for a password apart from having 1 of each type of character is good. I would suggest before you attempt any further coding using an exploratory technique, to write out the criteria you want to use for determining the password strength.

    The following is an adaption of your code to add in a second criteria. This is not a complete solution but may give you an idea of the process
    import java.util.Scanner;
    public class Forum {
    	public static void main(String[] args) {
    		Scanner ms = new Scanner(System.in);
    		String myString = ms.nextLine();
     
    		int strengthCount1 = checkPasswordStrength1(myString);
    		int strengthCount2 = checkPasswordStrength2(myString);
     
            if (strengthCount1 + strengthCount2 < 3)
                System.out.println("Password is weak");
            else if (strengthCount1 + strengthCount2 < 5)
                System.out.println("Password is medium");
            else if (strengthCount1 + strengthCount2 < 7)
                System.out.println("Password is good");
            else
                System.out.println("Password is very good");
    	}
     
    	private static int checkPasswordStrength1(String passw) 
        {
            int strengthCount=0;
            String[] partialRegexChecks = { ".*[a-z]+.*", // lower
                                            ".*[A-Z]+.*", // upper
                                            ".*[\\d]+.*", // digits
                                            ".*[@#$%]+.*" // symbols
            							};
     
            for (int i = 0; i < 4; i++)
            	if (passw.matches(partialRegexChecks[i]))
            		strengthCount+=1;
     
            return strengthCount;
        }
     
    	private static int checkPasswordStrength2(String passw) 
        {
    		int strengthCount=0;
    		if (passw.length() < 5)
    			strengthCount = 1;
    		else if (passw.length() < 8)
    			strengthCount = 2;
    		else 
    			strengthCount = 3;
     
            return strengthCount;
        }
     
    }
    Last edited by shahcat; June 19th, 2014 at 03:15 AM.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help with ArrayList Features

    @shahcat: Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly per the above link.

Similar Threads

  1. Java 1.7 features
    By Reddi.Java in forum Member Introductions
    Replies: 1
    Last Post: February 8th, 2013, 09:01 AM
  2. finding video features using JMF
    By divijasri in forum Java SE APIs
    Replies: 1
    Last Post: April 11th, 2012, 02:44 PM
  3. WORKING BUT SOME FEATURES NOT
    By kariolos in forum What's Wrong With My Code?
    Replies: 16
    Last Post: May 26th, 2011, 06:25 AM
  4. new features in bug tracking tools
    By ssiklib in forum Web Frameworks
    Replies: 0
    Last Post: April 5th, 2011, 02:34 AM
  5. CVS features in Eclipse
    By bbr201 in forum Java IDEs
    Replies: 5
    Last Post: August 11th, 2010, 06:12 AM