Results 1 to 5 of 5
  1. #1
    Fargo94 is offline Member
    Join Date
    May 2011
    Posts
    10
    Rep Power
    0

    Default Assistance with Basic authentication program

    I need to make a program based on the following specifications:

    A password consists of a 5 digit pin number, each digit is assigned a random number :1,2,3.

    PIN: 0 1 2 3 4 5 6 7 8 9
    NUM: 3 2 3 1 1 3 2 2 1 3

    U enter tthe correspoding number for each pin digit.

    u need to output random digits to the screen, accept input fromn the user and output whether or not the user's response correctly matches the PIN number. The program shoudl sue an array to assign random numbers from 1 -9

    Any starting points would be much appreciated

  2. #2
    Petr's Avatar
    Petr is offline Senior Member
    Join Date
    Jan 2011
    Location
    Russia
    Posts
    620
    Rep Power
    4

    Default

    Hi
    I recently made a like method. Look
    Java Code:
        private static final Random rd = new Random();
        private static List<String> generatePosition(List<String> list) {
            List<String> temp = new ArrayList<String>(list);
            List<String> result = new ArrayList<String>();
            int total = temp.size(), pos;
            for (int i=0;i!=total;++i) {
                pos = rd.nextInt(temp.size());
                result.add(temp.get(pos));
                temp.remove(pos);
            }
            return result;
        }
    Skype: petrarsentev
    http://TrackStudio.com

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Quote Originally Posted by Fargo94 View Post
    I need to make a program based on the following specifications:

    A password consists of a 5 digit pin number, each digit is assigned a random number :1,2,3.

    PIN: 0 1 2 3 4 5 6 7 8 9
    NUM: 3 2 3 1 1 3 2 2 1 3

    U enter tthe correspoding number for each pin digit.

    u need to output random digits to the screen, accept input fromn the user and output whether or not the user's response correctly matches the PIN number. The program shoudl sue an array to assign random numbers from 1 -9

    Any starting points would be much appreciated
    A good starting point is you writing some code.
    Actually, a good starting point is you writing out what the logic for this is, then write some code.

    Oh, and avoid txt spk...

  4. #4
    Fargo94 is offline Member
    Join Date
    May 2011
    Posts
    10
    Rep Power
    0

    Default New Development

    So I've done up some code, it is as follows;

    AuthenticateApp.java
    package authenticateapp;
    import java.util.Scanner;
    /**
    *
    * @author Markus
    */
    public class AuthenticateApp {

    public static void main(String[] args) {

    Authenticate AuthenticateInstance = new Authenticate();

    AuthenticateInstance.generateRandomNumbers();
    //AuthenticateInstance.userInput();
    }
    }

    AuthenticateApp.java

    package authenticateapp;
    import java.util.Scanner;
    /**
    *
    * @author Markus
    */
    public class Authenticate {

    // Actual password is 99508
    private static int[] actual_password = {9, 9, 5, 0, 8};
    // Array to hold randomly generated digits
    private static int[] random_nums = new int[10];
    // Array to hold the digits entered by the user to authenticate
    private static int[] entered_digits = new int[actual_password.length];

    // Randomly generate numbers from 1-3 for each digit
    public void generateRandomNumbers(){

    for (int i=0; i < 10; i++) {
    random_nums[i] = (int) (Math.random() * 3) + 1;
    }

    System.out.println("Welcome! To log in, enter the random digits from 1-3 that");
    System.out.println("correspond to your PIN number.");
    System.out.println();
    System.out.println("PIN digit: 0 1 2 3 4 5 6 7 8 9");
    System.out.print("Random #: ");

    for (int i=0; i<10; i++)
    {
    System.out.print(random_nums[i] + " ");
    System.out.println();
    System.out.println();
    }
    }
    //Accept and process user input
    public void userInput(){

    for (int i=0; i<s.length(); i++) {
    // Convert char to corresponding digit

    entered_digits[i] = s.charAt(i) - '0';
    }

    }
    // At this point, if the user typed 12443 then
    // entered_digits[0] = 1, entered_digits[1] = 2, entered_digits[2] = 4,
    // entered_digits[3] = 4, and entered_digits[4] = 3

    /****
    TO DO: fill in the parenthesis for the if statement so the isValid method
    is invoked, sending in the arrays actual_password, entered_digits, and
    random_nums as parameters
    ***/

    //if () // FILL IN HERE

    //System.out.println("Correct! You may now proceed."); }
    //else
    //{ System.out.println("Error, invalid password entered."); }

    /****

    TO DO: Fill in the body of this method so it returns true if a valid
    password response is entered, and false otherwise.

    For example, if: actual = {9,9,5,0,8}
    randnums = {1,2,3,1,2,3,1,2,3,1}

    then this should return true if:
    entered[0] == 1 (actual[0] = 9 -> randnums[9] -> 1)
    entered[1] == 1 (actual[1] = 9 -> randnums[9] -> 1)
    entered[2] == 3 (actual[2] = 5 -> randnums[5] -> 3)
    entered[3] == 1 (actual[3] = 0 -> randnums[0] -> 1)
    entered[4] == 3 (actual[4] = 8 -> randnums[8] -> 3)

    or in other words, the method should return false
    if any of the above are not equal.

    ****/

    public static boolean isValid(int[] actual, int[] entered, int[] randnums)
    {
    /* TO DO: FILL IN CODE HERE */
    return true;
    }
    }

    The remaining commented sections are teh sectiosn I still have left to do, any help or advice people could offer would be much appreciated.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    So.
    You have the logic there in the description.
    Surely you can code that since you've managed to code the rest of this.
    At least give it a shot.

Similar Threads

  1. HTTP Basic Authentication
    By abhinav04sharma in forum Networking
    Replies: 0
    Last Post: 02-28-2011, 05:43 AM
  2. Ladder Program (Need Assistance)
    By Grenade in forum Jobs Discussion
    Replies: 1
    Last Post: 12-14-2010, 11:21 PM
  3. Assistance needed ASAP: Postpix program
    By Debonairj in forum New To Java
    Replies: 18
    Last Post: 07-27-2010, 02:37 PM
  4. Replies: 7
    Last Post: 11-23-2009, 09:42 AM
  5. Basic authentication without a secure connection
    By Tokajac in forum Web Frameworks
    Replies: 0
    Last Post: 04-23-2009, 08:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •