Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My fith program: Password Generator
#1
This could have probably been done in a similar way, but, I got it done none the less.

Code:
import java.util.*;
import java.lang.*;
class pass
{
    public static void main(String[] args)
    {
        Scanner len = new Scanner(System.in);
        System.out.print("How many digits should be in your password?: ");
        int ilen = len.nextInt();
        while (0 < ilen)
        {
            Random number = new Random();
            int inumber = number.nextInt(34);
            ilen = ilen - 1;
            if (inumber == 1)
                System.out.print("a");            
            else if (inumber == 2)
                System.out.print("b");        
            else if (inumber == 3)
                System.out.print("c");
            else if (inumber == 4)
                System.out.print("d");
            else if (inumber == 5)
                System.out.print("e");
            else if (inumber == 6)
                System.out.print("f");
            else if (inumber == 7)
                System.out.print("g");
            else if (inumber == 8)
                System.out.print("h");
            else if (inumber == 9)
                System.out.print("i");
            else if (inumber == 10)
                System.out.print("j");
            else if (inumber == 11)
                System.out.print("k");
            else if (inumber == 12)
                System.out.print("l");
            else if (inumber == 13)
                System.out.print("m");
            else if (inumber == 14)
                System.out.print("n");
            else if (inumber == 15)
                System.out.print("o");
            else if (inumber == 16)
                System.out.print("p");
            else if (inumber == 17)
                System.out.print("q");
            else if (inumber == 18)
                System.out.print("r");
            else if (inumber == 19)
                System.out.print("s");
            else if (inumber == 20)
                System.out.print("t");
            else if (inumber == 21)
                System.out.print("u");
            else if (inumber == 22)
                System.out.print("w");
            else if (inumber == 23)
                System.out.print("x");
            else if (inumber == 24)
                System.out.print("y");
            else if (inumber == 25)
                System.out.print("z");
            else if (inumber == 26)
                System.out.print("1");
            else if (inumber == 27)
                System.out.print("2");
            else if (inumber == 28)
                System.out.print("3");
            else if (inumber == 29)
                System.out.print("4");
            else if (inumber == 30)
                System.out.print("5");
            else if (inumber == 31)
                System.out.print("6");
            else if (inumber == 32)
                System.out.print("7");
            else if (inumber == 33)
                System.out.print("8");
            else if (inumber == 34)
                System.out.print("9");





        }
    System.out.println("");
    }
}

EDIT: I made it so you can save this to a file. I probably could have made it so you didn't have to paste your password, but I think I may have rewrite a lot of stuff, and I'm very lazy Big Grin.

Code:
import java.util.*;
import java.lang.*;
import java.io.*;
class pass
{
    public static void main(String[] args)throws IOException
    {
        Scanner len = new Scanner(System.in);
        System.out.print("How many digits should be in your password?: ");
        int ilen = len.nextInt();
        while (0 < ilen)
        {
            Random number = new Random();
            int inumber = number.nextInt(34);
            ilen = ilen - 1;
            if (inumber == 1)
                System.out.print("a");            
            else if (inumber == 2)
                System.out.print("b");        
            else if (inumber == 3)
                System.out.print("c");
            else if (inumber == 4)
                System.out.print("d");
            else if (inumber == 5)
                System.out.print("e");
            else if (inumber == 6)
                System.out.print("f");
            else if (inumber == 7)
                System.out.print("g");
            else if (inumber == 8)
                System.out.print("h");
            else if (inumber == 9)
                System.out.print("i");
            else if (inumber == 10)
                System.out.print("j");
            else if (inumber == 11)
                System.out.print("k");
            else if (inumber == 12)
                System.out.print("l");
            else if (inumber == 13)
                System.out.print("m");
            else if (inumber == 14)
                System.out.print("n");
            else if (inumber == 15)
                System.out.print("o");
            else if (inumber == 16)
                System.out.print("p");
            else if (inumber == 17)
                System.out.print("q");
            else if (inumber == 18)
                System.out.print("r");
            else if (inumber == 19)
                System.out.print("s");
            else if (inumber == 20)
                System.out.print("t");
            else if (inumber == 21)
                System.out.print("u");
            else if (inumber == 22)
                System.out.print("w");
            else if (inumber == 23)
                System.out.print("x");
            else if (inumber == 24)
                System.out.print("y");
            else if (inumber == 25)
                System.out.print("z");
            else if (inumber == 26)
                System.out.print("1");
            else if (inumber == 27)
                System.out.print("2");
            else if (inumber == 28)
                System.out.print("3");
            else if (inumber == 29)
                System.out.print("4");
            else if (inumber == 30)
                System.out.print("5");
            else if (inumber == 31)
                System.out.print("6");
            else if (inumber == 32)
                System.out.print("7");
            else if (inumber == 33)
                System.out.print("8");
            else if (inumber == 34)
                System.out.print("9");





        }
        System.out.println("");
        Scanner syesno = new Scanner(System.in);
        int iyesno;
        System.out.println("1) Yes");
        System.out.println("2) No");
        System.out.print("Do you want to save this?: ");
        iyesno = syesno.nextInt();
        if (iyesno == 1)
        {
            Scanner swhatfor = new Scanner(System.in);
            String Stringwhatfor;
            Scanner spassw = new Scanner(System.in);
            String Stringpassw;
            System.out.print("What is this for?: ");
            Stringwhatfor = swhatfor.next();
            System.out.print("Please paste the password here: ");
            Stringpassw = spassw.next();        
            Writer output = null;
            File file = new File(Stringwhatfor);
            output = new BufferedWriter(new FileWriter(file));
            output.write(Stringpassw);
            output.close();
            System.out.println("Saved!");
        }
        else
        {
        }
                
    }
}

If anyone knows how to generate a random object out of a string
I.E:
String n = ['a','b','c']
then print a random object out of there
feel free to post it Big Grin
Reply
#2
in this post the source code has an "import java.util.Random;" in it. I cant understand the syntax but im sure you can find what he did to spit out random letters.
[Image: izsyo6.jpg]


Reply
#3
Code:
Random randomGen = new Random();
    private String randomizeInt() {
        int toInt = Integer.parseInt(jTextField4.getText());
        int randomIndex = randomGen.nextInt(toInt);
        String randomString = Integer.toString(randomIndex);
        return randomString;
    }

Code:
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
        jTextField5.setText(randomizeInt());
    }

Smile
My SMF Modifications:
http://anthony.vibrantvps.com/smf
Reply
#4
(11-30-2009, 07:44 PM)uber1337 Wrote: in this post the source code has an "import java.util.Random;" in it. I cant understand the syntax but im sure you can find what he did to spit out random letters.

Yeah, I saw that, But since I didn't fully understand everything used in that, I didn't want to get to ahead of myself. And I also used import java.util.Random, It is under import java.util.*
Also, does that make random numbers? I didnt think it did.
Reply
#5
It does create random numbers, the only thing I did with my generator was I made a user input whatever number of digits they wanted using a textfield, and it generated a random set of numbers according to the digits.

I can create a tutorial if you are stuck on anything.
My SMF Modifications:
http://anthony.vibrantvps.com/smf
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Java] Password Generator Version 3.0 CometJack 29 5,024 01-03-2012, 06:03 PM
Last Post: MineCrack
  Another Completly Nessacary Password Generator :D nevets04 10 2,291 05-03-2010, 01:50 AM
Last Post: JesusOfSuburbia
  Password Generator [Version 2] Project Evolution 9 2,085 03-13-2010, 10:45 PM
Last Post: Ⱳąŗɗ

Forum Jump:


Users browsing this thread: 1 Guest(s)