-2

How can I randomly generate a password in Java with the following elements:

  • The password must be minimum 5 en maximum 9 characters long.
  • The length of the password must be randomly chosen. For example the password can 5,6,7,8 or 9 characters long.
  • The first character of the password is the lenght of the password. For example if the password is 5 characters long, than is the first character of the password 5.
  • The following caracters of the password are unicodes of 255,65 or 126.
2
  • You have to write some code which will generate characters which meet the critera above. The simple/dump way is to repeatedly, randomly generate a String and check it meets all the criteria and if it doesn't, try again. Aug 30, 2015 at 15:19
  • What do you mean by the unicodes of 255, 65 and 126. Do you mean all the characters must be A, ~ or \u00ff Aug 30, 2015 at 15:20

1 Answer 1

0

Take a look at Apache's RandomStringUtils, but some of requirements, like a "The first character of the password is the lenght of the password" and similar you'll need to make by yourself, then you generate the base part of your password.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.