Newer
Older
package interfacemanualmocking;
import authentication.AuthenticationService;
import authentication.Strength;
public class AuthenticationByPasswordService implements AuthenticationService {
private DirectoryInterface directory;
private StrengthEstimationServiceInterface strengthEstimationService;
public void setStrengthEstimationService(StrengthEstimationServiceInterface strengthEstimationService) {
this.strengthEstimationService = strengthEstimationService;
}
public AuthenticationByPasswordService(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 ;
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);