how to generate password? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how to generate password?

27th Oct 2016, 9:15 AM
vishal pathak
vishal pathak - avatar
1 Answer
0
https://code.sololearn.com/cfyVDc1nMf5a/#java import java.util.Random; public class PasswordGenerator { public static void main( String[] args ) { generatePassword( 8 ); } static Random rnd = new Random(); static void generatePassword( int characterLength ) { // Characters to use in the password // Formatted to be able to quickly comment/uncomment upper-case, lower-case, numbers and symbols as needed String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz" + "1234567890" //+ "!£$%^&*()" ; String password = ""; for ( int i = 0; i < characterLength; i++ ) { password += characters.charAt( rnd.nextInt( characters.length() ) ); } System.out.println( password ); } }
27th Oct 2016, 9:14 PM
Liam
Liam - avatar