//JAVA
source code to generate random password
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
Note : Here
we have used random() to generate the password. It may change every time due to
use of random() method.
No comments:
Post a Comment