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

Thread: Password Program

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Password Program

    So in my program I'm supposed to modify my program with more security measures for users when they create a password. The exact wording for what I'm supposed to do is:
    1. What are some things you could do to increase the security? Modify your program.
    My answer is to require a certain amount of characters, and require both letters and numbers. However I do not know how to adjust my program to enforce this- Any help? My original program that has yet to be modified is below:

    /*Polt
    Lab 5
    COSC */
     
    import java.io.*;
    import javax.swing.*;
     
    public class Password{
      public static void main(String[] args)
          throws FileNotFoundException{
        String pw1;
        String pw2;
        PrintStream output = new PrintStream(new File("C:\\Programs\\Lab5\\password.txt"));
        do{
        pw1 = JOptionPane.showInputDialog("Enter a password");
        pw2 = JOptionPane.showInputDialog("Re-enter a password");
        if (!pw1.equals(pw2)){
          JOptionPane.showMessageDialog(null, "Re-enter your password", "Error", JOptionPane.ERROR_MESSAGE);}
        else{
          output.println(pw1);
        }
        }while(!pw1.equals(pw2));
      }
    }
    Last edited by JavaPF; October 19th, 2010 at 08:25 AM. Reason: Please use highlight tags around your code. See my sig.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Password Program

    Check out String (Java Platform SE 6) and Character (Java Platform SE 6) for useful functions.

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    computercoder (October 19th, 2010)

  4. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Password Program

    What is this program supposed to do?

    Is it ment to read or write to password.txt?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  5. #4
    Junior Member
    Join Date
    Oct 2010
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Password Program

    The program prompts the user to create a password, which they must then reenter to validate. If they match, the password is saved into a text file on my computer. If not, they repeat the process until they do, or until they hit cancel on the dialog box.
    I need to figure out a way to implement rules when the user creates passwords in order to have them more secure. For example what I was thinking is forcing the user to create a password that is at least 7 characters long, and also for them to use both letters AND numbers. However I am not sure how I would go about the letters and numbers part of coding.

  6. #5
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Password Program

    Did you read through the APIs for String and Character? Did you see anything useful?

  7. #6
    Junior Member
    Join Date
    Oct 2010
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Password Program

    I did
    I have modified my program to make sure the password is at least 7 characters long, however I am still trying to figure out which constructors I could use in order to check whether the password has more than just letters. My program currently:

     import java.io.*;
    import javax.swing.*;
     
    public class PasswordModified{
      public static void main(String[] args)
          throws FileNotFoundException{
        String pw1;
        String pw2;
        int length;
        PrintStream output = new PrintStream(new File("C:\\Programs\\Lab5\\password.txt"));
        do{
          pw1 = JOptionPane.showInputDialog("Enter a password");
          length = pw1.length();
          pw2 = JOptionPane.showInputDialog("Re-enter a password");
          if (!pw1.equals(pw2)){
            JOptionPane.showMessageDialog(null, "Password mismatch", "Error", JOptionPane.ERROR_MESSAGE);
          }
          else{
            output.println(pw1);
          }
          if (length<7){
            JOptionPane.showMessageDialog(null, "Your password must be at least 7 characters long", "Error", JOptionPane.ERROR_MESSAGE);
            pw2 = "";
          }
        }while(!pw1.equals(pw2));
      }
    }

  8. #7
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Password Program

    Why would you use a constructor to determine whether a String contains both chars and non-chars?

  9. #8
    Junior Member
    Join Date
    Oct 2010
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Password Program

    I don't know what to do, so I'm trying to figure something out by researching all my options at the moment. But thats why I posted here. Since Im lost on how to figure it out.

  10. #9
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Password Program

    Like I said, the secret lies in looking through the APIs and playing around with the methods. If you have a specific question about one of the methods, post an SSCCE that demonstrates what you've tried, and we'll go from there.

    If you're stuck on the algorithm, think about how you would do it "by hand". What directions would you give to somebody who has no idea how to tell whether a password has both characters and non-characters in it?

  11. #10
    Junior Member
    Join Date
    Oct 2010
    Posts
    8
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Password Program

    So far Ive been trying to use a loop. However now I cant figure out how to make sure that if it finds a number quit immedietly without showing the message that there needs to be a number, in addition to not showing the message until it finishes checking the whole password(aka input)



    for (int count = 0; count < length; count++) {
            if (Character.isDigit(pw1.charAt(count))){
              count = length;
            }
            else{
              JOptionPane.showMessageDialog(null, "Your password must include a number", "Error", JOptionPane.ERROR_MESSAGE);
              count = length;
              pw2 = "";
            }
          }

  12. #11
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Password Program

    Quote Originally Posted by computercoder View Post
    So far Ive been trying to use a loop. However now I cant figure out how to make sure that if it finds a number quit immedietly without showing the message that there needs to be a number, in addition to not showing the message until it finishes checking the whole password(aka input)
    Branching Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)

    But what happens if the user enters a password that is all digits? And don't you want to accept a password that includes both letters and punctuation, but not digits?

    You could also check out Pattern (Java Platform SE 6)

Similar Threads

  1. [SOLVED] password denied
    By chronoz13 in forum AWT / Java Swing
    Replies: 3
    Last Post: January 28th, 2010, 09:22 PM
  2. [SOLVED] Password screens
    By Dave in forum AWT / Java Swing
    Replies: 7
    Last Post: August 26th, 2009, 06:37 AM
  3. password
    By 5723 in forum Algorithms & Recursion
    Replies: 9
    Last Post: July 9th, 2009, 05:26 AM
  4. [SOLVED] java password
    By pwngrammer in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: June 15th, 2009, 09:49 AM
  5. Java password generator program to generate 8 random integers
    By Lizard in forum What's Wrong With My Code?
    Replies: 3
    Last Post: May 16th, 2009, 07:49 AM