Comp Sci How to Create a Java Program for Generating Custom Passwords?

  • Thread starter Thread starter Cia
  • Start date Start date
  • Tags Tags
    Generator Java
Click For Summary
The discussion focuses on creating a Java program for generating custom passwords based on user-selected criteria. Users can choose from four options for password composition, including lowercase letters, a mix of lowercase and uppercase letters, lowercase, uppercase, and numbers, or all of the above plus punctuation. Issues arise with the logic in the while loops used to validate character ranges, particularly with the use of negation and logical operators, leading to unexpected symbols in generated passwords. Participants emphasize the importance of correctly structuring the while loop conditions to ensure valid character selection. Understanding the logical expressions and their negations is essential for resolving these issues and improving the program's functionality.
  • #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
2K
  • · 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
2K