Hi,
As you may figure out from my source code, I dont think i have a really bright future in java... I'm supposed to write this password creating program using the method of ;
public static String passwordGenerat or(int n, int m)
i would much appreciate it if someone can have an eye on it..
As you may figure out from my source code, I dont think i have a really bright future in java... I'm supposed to write this password creating program using the method of ;
public static String passwordGenerat or(int n, int m)
i would much appreciate it if someone can have an eye on it..
Code:
import javax.swing.JOptionPane;
public class PasswordMethodA {
public static void main(String[]args) {
int option = 0;
String pass = "";
while (option == 0)
{
// Displaying out the choices user would like to have in creating different types of passwords
String choiceStr = JOptionPane.showInputDialog("Welcome to the password generator. Here are types of passwords you can select. "+
"\n1 : lower case letters only."+
"\n2 : upper case letters only."+
"\n3 : numbers only."+
"\n4 : characters and symbols."+
"\nPlease select one : " );
int choice = Integer.parseInt(choiceStr);
int pass = passwordGenerator(pass, choice);
JOptionPane.showMessageDialog(null,"Your password is " + pass);
}
public static String passwordGenerator(int pas, int m)
{
String pas = null;
int pas = 0;
int n = 0;
double r = 0;
if (m == 1)
{
JOptionPane.showMessageDialog(null, m);
for(int i = 1; i<7; i++){
n = (int)(Math.random()*26);
pas = pas + "abcdefghijklmqnoprstuvwxyz".charAt(n);
}
}
else if (m == 2)
// Creating upper case password if the user typed '2'
{
JOptionPane.showMessageDialog(null,m);
for(int i = 1; i<7; i++){
n = (int)(Math.random()*26);
pas = pas + "ABCDEFGHIJKLMQNOPRSTUVWXYZ".charAt(n);
}
}
// Creating an upper case and numbers password if the user typed '3'
else if(m == 3)
{
JOptionPane.showMessageDialog(null,m);
for(int i = 1; i<7; i++){
n = (int)(Math.random()*62);
pas = pas + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(n);
}
}
// Creating password using numbers, lowercase, uppercase and 9 symbols if the user typed '4'
else if(m == 4)
{
JOptionPane.showMessageDialog(null, m);
String aStr = JOptionPane.showInputDialog("How many digited password do you want to create?");
int a = Integer.parseInt(aStr);
for(int i = 1; i<a; i++){
n = (int)(Math.random()*70);
pas = pas + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@?[\\]^-'".charAt(n);
}
// Making sure symbols are added for the last choice.
n = (int)(Math.random()*a);
int sym = (int)(Math.random()*8);
a = pas.length();
pas = pas.substring(0,n)+"@?[\\]^-'".charAt(sym)+pas.substring(n,a);
return pas;
}
}
// Asking if the user wants to create a new password
JOptionPane.showMessageDialog(null,"If you want to create another password press 0; if not press 1; For cancel press 2." + option);
pass="";
}
Comment