-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserPasswordMatcher.java
64 lines (59 loc) · 1.77 KB
/
UserPasswordMatcher.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//******************************************************************************
//
// File: UserPasswordMatcher.java
// Package: ---
// Unit: Class UserPasswordMatcher
//
// The snippet of code for hashing the password was taken from the example snippets on the course website
//
// Author: Marko Galesic
//******************************************************************************
import java.util.*;
import java.util.concurrent.TimeUnit;
/**
* Objects of this class match one user from a password
* hash database against all the password hashes in a
* dictionary
*
* @author Marko Galesic
*/
public class UserPasswordMatcher extends Thread
{
// Hidden data members
private SynchronizedPlaintextPassword plaintextPassword;
private String username;
/**
* Constructor for UserFromPasswordHash class takes a dictionary and a database for lookup
*
* @param dictionary the dictionary of passwords
* @param database the database of password, username pairs
*/
public UserPasswordMatcher(String username, SynchronizedPlaintextPassword plaintextPassword)
{
this.plaintextPassword = plaintextPassword;
this.username = username;
}
/**
* Block until plaintext pasword is available - then print it out with a username
*/
@Override
public void run()
{
// Wait for plaintext password
try
{
plaintextPassword.latch.await((long)10.0, TimeUnit.SECONDS);
}
catch(InterruptedException e)
{
System.err.println("Error while waiting for plaintext password.");
}
// Get plaintext password
String password = plaintextPassword.getPlaintextPassword(username);
// Print out username password combination
synchronized(System.out)
{
if (password != "" ) System.out.println(username + " " + password); // Printout the user \ password combo
}
}
}