0% found this document useful (0 votes)
3 views

Java Lab 11

The document outlines a Java lab assignment focused on arrays, loops, and file handling. It requires creating a Java program that reads common password hashes from 'lab11pt1.txt' into a String array and checks for matches against usernames and hashed passwords in 'lab11pt2.txt'. The assignment includes specific coding instructions and examples for file reading and string manipulation.

Uploaded by

arya.santosh2007
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Java Lab 11

The document outlines a Java lab assignment focused on arrays, loops, and file handling. It requires creating a Java program that reads common password hashes from 'lab11pt1.txt' into a String array and checks for matches against usernames and hashed passwords in 'lab11pt2.txt'. The assignment includes specific coding instructions and examples for file reading and string manipulation.

Uploaded by

arya.santosh2007
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Java Lab 11 – Arrays, loops and files

 Create a new Java file (empty Java file), save it to your H: drive, call it lab11
 Insert the following code to set up your program:
 Be sure to copy the test text files to the location where you saved your Java file

import java.util.Scanner;

import java.io.*;

public class lab11 {

public static void main (String args[]) throws IOException{

File doc = new File("lab11pt1.txt");

Scanner commonPasswords = new Scanner(doc);

File doc2 = new File("lab11pt2.txt");

Scanner stolenFile = new Scanner(doc2);

// Insert your while loop code here

commonPasswords.close();

stolenFile.close();

100pt:

 Create a program that will read in all of the information in the file lab11pt1.txt and store it in a
String array of size 20.
 This first file contains a list of common password hashes. Use the information stored in this
array to search through lab11pt2.txt, which contains a leaked list of usernames and passwords
from a website. Print out the username and the hash of any matches that you find.

Notes:

The leaked file contains information in the format:

Username1,hashedpassword
Username2,hashedpassword2

Use the String split() method to store these in an array as you read through the file. Notes:
Create a String array:

String[] strArray = new String[10];

String split():

String line = "Username,45hjksdf954la";


String[] splitLine = line.split(",");
System.out.println(splitLine[0]); //Prints "Username"

String comparisons:

if(splitLine[1].equals(passwordArray[0]){

// Do Something

Use the following while loop to read in the file, line by line:

while(fileInput.hasNextLine()){

String line = fileInput.nextLine();

// Do whatever you want with the String variable line

You might also like