Password generator

  • 28
  • Locked
Implement the getPassword() method, which must return a ByteArrayOutputStream with the bytes comprising the password. Password requirements: 1) 8 characters. 2) Only numbers and uppercase and lowercase Latin letters. 3) At least one numeral, one lowercase letter, and one uppercase letter.
You can't complete this task, because you're not signed in.
Comments (3)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Justin Smith
Level 38 , Greenfield, USA, United States
23 August 2022, 22:37
Found it really weird that the official solution does not use Collections.shuffle to randomize the order after generating the sequence. The way they have it set up, the 6th character is always a number, the 7th character is always a lower-case letter, and the 8th character is always an upper-case character. That's a pretty heavy knock against the randomness of the password. Don't get me wrong, it's an excellent task and thankfully there are no weird validator shenanigans forcing you to use a specific solution.
Jurij Thmsn
Level 29 , Flensburg, Germany
25 May 2021, 15:18
Really enjoyed this exercise 🤡
Level 25 , Lucca, Italy
14 January 2021, 18:51
Nice task, i create a getCharacter method that return a random char that could be a Number(0-9) a Lowercase Letter or an UpperCase Letter This method create at the beginning a random number that could be 0,1 or 2. I need this number for a switch statment where : case 1 - generate random number; case 2 - generate random lower letter; case 3 - generate random upper letter; Then i create a method createPassword() witch call the getCharacter method 8 times(like the length of the required password) and check if the 3 requirement are satisfacted . If yes return the password as a string; If no, call the method himself using recursion; I used StringBuilder, the str.matches(regex) method, and an ASCII table Hope this can help