From 2cbc2122dea218a05f87bcece48ab551c67faf88 Mon Sep 17 00:00:00 2001 From: Akkichau <92620285+Akkichau@users.noreply.github.com> Date: Fri, 21 Oct 2022 17:31:05 +0530 Subject: [PATCH] Create Password_Generator.java --- Password_Generator.java | 110 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 Password_Generator.java diff --git a/Password_Generator.java b/Password_Generator.java new file mode 100644 index 0000000..0b02a4a --- /dev/null +++ b/Password_Generator.java @@ -0,0 +1,110 @@ +/* +Date: 21/10/2022 +Start Coding +*/ +// Java code to explain how to generate random +// password + + +// Here we are using random() method of util +// class in Java + +import java.util.*; + + + +public class NewClass +{ + + public static void main(String[] args) + + { + + // Length of your password as I have choose + + // here to be 8 + + int length = 10; + + System.out.println(geek_Password(length)); + + } + + + + // This our Password generating method + + // We have use static here, so that we not to + + // make any object for it + + static char[] geek_Password(int len) + + { + + System.out.println("Generating password using random() : "); + + System.out.print("Your new password is : "); + + + + // A strong password has Cap_chars, Lower_chars, + + // numeric value and symbols. So we are using all of + + // them to generate our password + + String Capital_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + String Small_chars = "abcdefghijklmnopqrstuvwxyz"; + + String numbers = "0123456789"; + + String symbols = "!@#$%^&*_=+-/.?<>)"; + + + + + + String values = Capital_chars + Small_chars + + + numbers + symbols; + + + + // Using random method + + Random rndm_method = new Random(); + + + + char[] password = new char[len]; + + + + for (int i = 0; i < len; i++) + + { + + // Use of charAt() method : to get character value + + // Use of nextInt() as it is scanning the value as int + + password[i] = + + values.charAt(rndm_method.nextInt(values.length())); + + + + } + + return password; + + } +} + +/* +Output : +Generating password using random() : +Your new password is : KHeCZBTM;- +*/