Results 1 to 5 of 5
- 05-13-2011, 11:23 AM #1
Member
- Join Date
- May 2011
- Posts
- 10
- Rep Power
- 0
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
- 05-13-2011, 11:39 AM #2
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
- 05-13-2011, 12:12 PM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
- 05-16-2011, 09:18 PM #4
Member
- Join Date
- May 2011
- Posts
- 10
- Rep Power
- 0
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.
- 05-17-2011, 09:22 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
HTTP Basic Authentication
By abhinav04sharma in forum NetworkingReplies: 0Last Post: 02-28-2011, 04:43 AM -
Ladder Program (Need Assistance)
By Grenade in forum Jobs DiscussionReplies: 1Last Post: 12-14-2010, 10:21 PM -
Assistance needed ASAP: Postpix program
By Debonairj in forum New To JavaReplies: 18Last Post: 07-27-2010, 01:37 PM -
Need to end program by typing quit and not -1!!! I have pasted my code for assistance
By sarchie109 in forum New To JavaReplies: 7Last Post: 11-23-2009, 08:42 AM -
Basic authentication without a secure connection
By Tokajac in forum Web FrameworksReplies: 0Last Post: 04-23-2009, 07:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks