From 4ca8f94f28914883bb4e781c58ca854a1dfc0762 Mon Sep 17 00:00:00 2001 From: Karan Patel <96780293+karanop001018@users.noreply.github.com> Date: Sat, 21 Oct 2023 18:23:09 +0530 Subject: [PATCH] Add files via upload --- Password Generator/GeneratePassword.class | Bin 0 -> 3676 bytes Password Generator/GeneratePassword.java | 113 ++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 Password Generator/GeneratePassword.class create mode 100644 Password Generator/GeneratePassword.java diff --git a/Password Generator/GeneratePassword.class b/Password Generator/GeneratePassword.class new file mode 100644 index 0000000000000000000000000000000000000000..19d552c01ccc46f4d401813f47c4d521be9da7b0 GIT binary patch literal 3676 zcmcImX;%|x6n@?i7zm@pU2qE)HHZjStxMEaQx`NKHHwO@IwS*(OfoTJUZ3}tDw$3rgKhS^nc z(&+NCk=(9S@qn~lFln32=_x}qAT?I0SdBFTb0;-+o4HYKNSCQDi}nmo573Bq ztX0sVVjVikn3LhuKv?pW!=pg2m*iBXn9FGu!SwhcbfH_p1{Dutqrj3W_;JfL*>jep zs?N3&MuDYYUg{e^)}&@kCbe0`L)gOVq+ACA-BkiF+xV;Rws}m!Hi6mYh$MChG3-#V zQ^hVk%$k&?o-2b*M%2P+ad_C&*)x7r=^@rW(1@+rtzr-2%*ib{Q?HiOWK#?5Rk08I z+59ZBz={g(;bJyr6S*r{%;ii&&+`}r(4*oY4iQ32rSu$)TB{rFG33c8W*oB`^ho;p zBz=bkEPwb@VSE*z6#CrVM_iTj$4Xu3OdJxxnXsp5m}xy9LO+r!j><7pZ(FWR!GJ)E zQ-^{aFNQtd<<1%RpoMS@H6fhDpn_8>9>)` zoPseGCO9?S>E*C0Cx@1@^*lTEf@T)=!@~lLqj7&hCUs&YCvK(L%S{O*tGk2is5T_K zJDAZ74!(uaQ&r|E>(Y=kMzWgCp)as;hC#Q(XI=*0Md(>cTT6}gk`Nbh(@f)RdN<2W zEi;tX+9oHYe}=Yo%j`>KuVjcJgpyV#?QwSeDJRtmS%jd(=u7 zn(FX$2+!bI1<%R*=y`!Qr%N6GM)ra=rpqzU_I9tReXNL;XE$B_X|CBf7QI9=WhYeMO-t@q+#o^dc4RnTDsRGrCU86 z85)noiv`=tM2_(e;|Ywouo0uMU66>EL%57r6uhe9HN4LAGKGkQQyyAr!zCITGyebn z{{Kmtk+BM)TL(X(6=H|&nTQPIO@Yeg$D_Zg9&gJrR};p&zB|EJV{aD5!gx<$jh_|I zh3_bpYC6zVi)+&D`zk)bhw@6u<@799v(73G{E@qjQpUV4u)%LqDfdB_PjS0M|3spH zD$zfali(i3q<+4rXH$A?Cg?8&Hv0{yg{~B|4}@_;?q(I|yF_;#zLp!*H!3dRVi*?% z)SfK&*SN{;RWB&GDX?lvx4PY3c^Vb`$i-x4RTA$WU9=K3z*QAczw`@he|=1@kGzKm&hrIL~*fx`7U)i#Zce62Dkp6hFjx|WcMCBYk51i^0hRmHMb7?liD0aeNY#G?p zYCxd demoPassword = Stream.concat(getRandomNumbers(2), + Stream.concat(getRandomSpecialChars(2), + Stream.concat(getRandomAlphabets(2, true), getRandomAlphabets(2, false)))); + + // create a list of Char that stores all the characters, numbers, and special + // characters + List listOfChar = demoPassword.collect(Collectors.toList()); + + // use shuffle() method of the Collections to shuffle the list elements + Collections.shuffle(listOfChar); + + // generate a random string(secure password) by using list stream() method and + // collect() method + String password = listOfChar.stream() + .collect(StringBuilder::new, StringBuilder::append, StringBuilder::append) + .toString(); + + // return RandomStringGenerator password to the main() method + return password; + } + + // create getRandomSpecialChars() method that returns a Stream of special chars + // of the specified length + public static Stream getRandomSpecialChars(int length) { + + Stream specialCharsStream; + + // create instance of SecureRandom + Random random = new SecureRandom(); + + // use ints() method of random to get IntStream of special chars of the + // specified length + IntStream specialChars = random.ints(length, 33, 45); + specialCharsStream = specialChars.mapToObj(data -> (char) data); + + // return stream to the main() method + return specialCharsStream; + } + + // create getRandomNumbers() method that returns a Stream of numbers of the + // specified length + public static Stream getRandomNumbers(int length) { + + Stream numberStream; + + // create instance of SecureRandom + Random random = new SecureRandom(); + + // use ints() method of random to get IntStream of number of the specified + // length + IntStream numberIntStream = random.ints(length, 48, 57); + numberStream = numberIntStream.mapToObj(data -> (char) data); + + // return number stream to main() method + return numberStream; + } + + // create getRandomAlphabets() method that returns either a stream of upper case + // chars or stream of lower case chars + // of the specified length based on the boolean variable check + public static Stream getRandomAlphabets(int length, boolean check) { + + Stream lowerUpperStream; + + // for lower case stream + if (check == true) { + // create instance of SecureRandom + Random random = new SecureRandom(); + + // use ints() method of random to get IntStream of lower case letters of the + // specified length + IntStream lCaseStream = random.ints(length, 'a', 'z'); + lowerUpperStream = lCaseStream.mapToObj(data -> (char) data); + } + // for upper case stream + else { + // create instance of SecureRandom + Random random = new SecureRandom(); + + // use ints() method of random to get IntStream of upper case letters of the + // specified length + IntStream uCaseStream = random.ints(length, 'A', 'Z'); + lowerUpperStream = uCaseStream.mapToObj(data -> (char) data); + } + + // return lowerUpperStream to main() method + return lowerUpperStream; + + } + +} \ No newline at end of file