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

Thread: Random Password

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Posts
    7
    My Mood
    Yeehaw
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Random Password

    I'm a java beginner, i don't know english well. i do read tutorials, but i can't get all stuff about java. Now i'm trying to code a random pasword generator.. Rules :
    * maxlenght must be 8 characters
    * i can use only digits and lower cases.
    * three or more characters can't be the same.
    * the password must be different when i run the program again...

    Best Regards...


  2. #2
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Random Password

    Break it down into tasks:
    1. How to generate a random lowercase letter or digit.
    2. How to avoid more than 2 of the same character.
    3. How to stop when you have 8 characters.
    4. How to ensure the random selection is different each time you run it.

    Some tips: Before starting to write any code, figure out exactly how you plan to solve each of these problems. Make sure every step is worked out on paper in your native language before trying to translate it into Java. Designing an application and writing Java code are separate tasks, and each requires thought and care. Trying to do both at the same time will end in tears...

    There are two simple ways in the SDK to get a random number - the Math.random() method, which gives you a double (floating-point) random number, and the Random class, which has a bunch of methods for random numbers. There is another approach - you could shuffle a list of characters to randomize it. The Collections.shuffle(..) methods will shuffle a list.

    You also need to think about how to ensure you use no more than 2 of the same character - consider how you can check whether a character has already been used, and how to prevent it being selected again.

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

    JavaPF (July 18th, 2011)

  4. #3
    Junior Member
    Join Date
    Jul 2011
    Posts
    7
    My Mood
    Yeehaw
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Random Password

    i do know built an alghorithm but i can't use methots/functions... do need my program "shuffle" ?

  5. #4
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Random Password

    How you do it is up to you, but it might help to think of your set of possible password characters as a pack of cards, and consider how you could select 8 cards at random...

  6. #5
    Junior Member
    Join Date
    Jul 2011
    Location
    PUNE/MUMBAI
    Posts
    5
    My Mood
    Busy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Random Password

    use javascript to get the job done on the client side along with jsp......



    ashishkumar haldar.

  7. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Random Password

    Quote Originally Posted by ashishkumar haldar View Post
    use javascript to get the job done on the client side along with jsp......



    ashishkumar haldar.
    I'm confused or maybe missed something. How does this apply to the original posters question?

  8. #7
    Junior Member
    Join Date
    Jul 2011
    Posts
    7
    My Mood
    Yeehaw
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Random Password

    Quote Originally Posted by ashishkumar haldar View Post
    use javascript to get the job done on the client side along with jsp......



    ashishkumar haldar.
    I just know C n C++ how can i this job with javascript ?

Similar Threads

  1. Generation of random number using random class
    By JavaPF in forum Java SE API Tutorials
    Replies: 1
    Last Post: December 7th, 2011, 05:46 PM
  2. Password Tester GUI HELP
    By java.kid21 in forum Object Oriented Programming
    Replies: 3
    Last Post: December 7th, 2010, 11:35 PM
  3. password.java
    By nickpuma19 in forum Object Oriented Programming
    Replies: 5
    Last Post: November 11th, 2010, 01:29 AM
  4. password
    By 5723 in forum Algorithms & Recursion
    Replies: 9
    Last Post: July 9th, 2009, 05:26 AM
  5. Generation of random number using random class
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: April 16th, 2009, 06:10 AM