//wap to generate password?
import java.util.Random;
public class GeneratePassword {
public static char [] generatepassword(int len)
{
System.out.println("Generating password using random() : ");
System.out.print("Your new password is : ");
String uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String lowercase = "abcdefghijklmnopqrstuvwxyz";
String digit = "0123456789";
String specialsymbol = "!@#$%^&*_=+-/.?<>)";
String values=uppercase+lowercase+digit+specialsymbol;
Random r1=new Random();
char [] password=new char[len];
for(int i=0;i<len;i++)
{
password[i]=values.charAt(r1.nextInt(values.length()));
}
return password;
}
public static void main(String[] args) {
System.out.println(GeneratePassword.generatepassword(8));
}
}
import java.util.Random;
public class GeneratePassword {
public static char [] generatepassword(int len)
{
System.out.println("Generating password using random() : ");
System.out.print("Your new password is : ");
String uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String lowercase = "abcdefghijklmnopqrstuvwxyz";
String digit = "0123456789";
String specialsymbol = "!@#$%^&*_=+-/.?<>)";
String values=uppercase+lowercase+digit+specialsymbol;
Random r1=new Random();
char [] password=new char[len];
for(int i=0;i<len;i++)
{
password[i]=values.charAt(r1.nextInt(values.length()));
}
return password;
}
public static void main(String[] args) {
System.out.println(GeneratePassword.generatepassword(8));
}
}
o/p:-
Generating password using random() :
Your new password is : D+8$AqEd
No comments:
Post a Comment