Newer
Older
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
65
package automaticmocking;
import authentication.AuthenticationService;
import authentication.Strength;
import interfacemanualmocking.DirectoryInterface;
import interfacemanualmocking.StrengthEstimationServiceInterface;
public class AuthenticationByPasswordService implements AuthenticationService {
private interfacemanualmocking.DirectoryInterface directory;
private interfacemanualmocking.StrengthEstimationServiceInterface strengthEstimationService;
public void setStrengthEstimationService(interfacemanualmocking.StrengthEstimationServiceInterface strengthEstimationService) {
this.strengthEstimationService = strengthEstimationService;
}
public AuthenticationByPasswordService(interfacemanualmocking.DirectoryInterface directory, StrengthEstimationServiceInterface strengthEstimationService) {
this.directory = directory;
this.strengthEstimationService = strengthEstimationService;
}
@Override
public boolean isAMatch(String identifier, String autenthicationData) {
String match = directory.getMatch(identifier);
return match.equals(autenthicationData);
}
@Override
public Strength dataStrenth(String autenthicationData) {
int datasize = autenthicationData.length();
int alphabetSize = 142;
int strength = strengthEstimationService.equivalentBitLength(alphabetSize,datasize);
Strength result = null ;
if( strength >= 0 && strength <= 49 ) {
result = Strength.VERY_WEAK;
}
else if ( strength >= 50 && strength <= 79 ) {
result = Strength.WEAK;
}
else if ( strength >= 80 && strength <= 99 ) {
result = Strength.REGULAR;
}
else if ( strength >= 100 ) {
result = Strength.STRONG;
}
return result;
}
public void setDirectory(DirectoryInterface directory) {
this.directory = directory;
}
}
//private StrengthEstimationServiceInterface dataStrenth(String autenthicationData) {
// int alphabetSize = 0;
// int datasize = autenthicationData.length();
//return strengthEstimationService.equivalentBitLength(alphabetSize, datasize);
//}