How to Create a Java Program for Generating Custom Passwords?

  • Context: Comp Sci 
  • Thread starter Thread starter Cia
  • Start date Start date
  • Tags Tags
    Generator Java
Click For Summary

Discussion Overview

The discussion revolves around creating a Java program for generating custom passwords. Participants share code snippets and explore different approaches to implement password generation based on user-selected criteria, including the inclusion of lowercase letters, uppercase letters, numbers, and punctuation.

Discussion Character

  • Homework-related
  • Technical explanation

Main Points Raised

  • One participant presents a Java program that allows users to select the type of characters to include in the password and specify the password length.
  • The program includes options for generating passwords with only lowercase letters, a combination of lowercase and uppercase letters, lowercase, uppercase, and numbers, or all of these plus punctuation.
  • Another participant shares a similar code structure but does not complete the implementation, indicating a focus on the same password generation logic.
  • Both participants utilize a random number generator to select characters based on the user's choices, but the implementation details vary slightly.

Areas of Agreement / Disagreement

There is no consensus on a single implementation, as participants present different versions of the code with varying levels of completion and detail. The discussion remains unresolved regarding the optimal approach to password generation.

Contextual Notes

Some code snippets are incomplete, and there are potential issues with the random number generation logic that may affect character selection. The discussions do not clarify these limitations fully.

  • #31
Not the solution to the problem, but no one commented yet that, unless you are generating huge passwords (and in that case Java is by far not the best choice), you should use the Character.isLowerCase() and Character.isUpperCase() methods. It is considered superior due to a series of reasons (some somewhat stupid, tagged as 'enterprisey') that are sold by the name 'Software Engineering'.
 
Physics news on Phys.org
  • #32
mafagafo said:
Not the solution to the problem, but no one commented yet that, unless you are generating huge passwords (and in that case Java is by far not the best choice), you should use the Character.isLowerCase() and Character.isUpperCase() methods. It is considered superior due to a series of reasons (some somewhat stupid, tagged as 'enterprisey') that are sold by the name 'Software Engineering'.

Mark44 said:
@Cia, where are the other entries in the table? It looks like you filled out only the column for the first comparison.
Mark44 said:
It can't be in the two ranges - it can only be in the first range or the second range, or neither.

!(randNum>=65) && (randNum<=90) || (randNum>=97) && (randNum<=122)

Each of the four comparisons above will evaluate to true or false. To help you understand what your code is doing, please state what each comparison evaluates to for each of the following numbers.

Code:
Number          Comparison 1(T/F)     Comparison 2(T/F)   Comparison 3(T/F)    Comparison 4(T/F)
66                        f                    f                   f                     f
93                        t                    t                   t                     t
101                      f                    f                   f                     f
123                      t                    t                   t                     t
 
Last edited by a moderator:
  • #33
Did you even try?
 
  • #34
mafagafo said:
Did you even try?
that is what the ranges should be because "!" means not. Am saying if a number is not in the range for example 66 is our number and the range id !(randNum>=65)
since 66 is greater than or equal to 65 it statement would be false
 
  • #35
Are you up to try the two methods I suggested earlier? When do you want to use the int? When it is lower OR upper, right? Implement it that way.
 
  • #36
mafagafo said:
Are you up to try the two methods I suggested earlier? When do you want to use the int? When it is lower OR upper, right? Implement it that way.
I can't use the two methods that you suggest earlier because, it would be "advanced" in my class now. However, my teacher said that she likes what she seeing? But, even she is giving me enough help :/
 
  • #37
Think about the truth table again. Mark set up something really good but you did not honor his efforts. If you do not understand how to fill the TT, look on Wikipedia how to do it.

Let's use 0 for false and 1 for true?

\begin{array}{| c | c | c | c | c |} \hline<br /> &amp; ! \ge 65 &amp; \le 90 &amp; \ge 97 &amp; \le 122 \\<br /> 66 &amp;0&amp; &amp; &amp; \\<br /> 93 &amp;0&amp; &amp; &amp; \\<br /> 101 &amp;0&amp; &amp; &amp; \\<br /> 123 &amp;0&amp; &amp; &amp; \\<br /> \hline<br /> \end{array}

Now fill the rest!
 
Last edited:
  • #38
@Cia,
Here are the four comparisons again:
Code:
!(randNum>=65) && (randNum<=90) || (randNum>=97) && (randNum<=122)

In the table you filled out in post #32, you have F, F, F, and F in the first row when randNum is 66. The first, third, and fourth values are correct for the code you have (shown again up above), but the second one is wrong -- randNum IS less than or equal to 90. When we say that a certain number x is between, say 5 and 10, it has to be true that x ≥ 5 AND x ≤ 10. Both of these have to be true if x is somewhere between the two endpoints.

In contrast, if x is 20, we have x ≥ 5 again, but x > 10, so this x is not between 5 and 10.

In the second row of your table in post #32, you have two mistakes. If randNum is 93, the values you have for the four comparisons are T, T, T, and T.
For the first and second comparisons, the correct values are F and F.
 

Similar threads

  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K