❮ Previous Next ❯

JAVA source code to generate random password

Hi frnds, here I am going to represent to generate random password. only core java file.
Required Files:

  1. PasswordExample.java

Example of generate random password

In this example, we are using only coreJAVA.
PasswordExample.java

 package java8s;

 import java.util.*;
 public class PasswordExample
 {

    public static void main(String[] args)
      {

         int length = 10;
         System.out.println(silanPassword(length));


      }

    static char[] silanPassword(int len)
      {
         System.out.print("Your new password is : ");


         String uchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
         String lchars = "abcdefghijklmnopqrstuvwxyz";
         String numbers = "0123456789";
         String symbols = "!@#$%^&*_=+-/.?<>)";


         String values = uchars + lchars +numbers + symbols;
       


         Random rd = new Random();

         char[] password = new char[len];

         for (int i = 0; i < len; i++)
         {

           password[i] =
           values.charAt(rd.nextInt(values.length()));

         }
         return password;
      }
 }

OUTPUT


Your new password is : mR!XPdfVmg





❮ Previous Next ❯

Follow Us




  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved