Skip to content
Snippets Groups Projects
AuthenticationByPasswordService.java 1.98 KiB
Newer Older
  • Learn to ignore specific revisions
  • package interfacemanualmocking;
    
    import authentication.AuthenticationService;
    import authentication.Strength;
    
    public class AuthenticationByPasswordService implements AuthenticationService {
        private DirectoryInterface directory;
    
        private StrengthEstimationServiceInterface strengthEstimationService;
    
    
    MEDEDJI Setondji's avatar
    MEDEDJI Setondji committed
        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;
    
    MEDEDJI Setondji's avatar
    MEDEDJI Setondji committed
            int strength = strengthEstimationService.equivalentBitLength(alphabetSize,datasize);
    
            Strength result = null ;
    
            if( strength >= 0 && strength <= 49 ) {
    
    MEDEDJI Setondji's avatar
    MEDEDJI Setondji committed
                result = Strength.VERY_WEAK;
    
    MEDEDJI Setondji's avatar
    MEDEDJI Setondji committed
            else if ( strength >= 50 && strength <= 79 ) {
                result = Strength.WEAK;
    
    MEDEDJI Setondji's avatar
    MEDEDJI Setondji committed
            else if ( strength >= 80 && strength <= 99 ) {
                result = Strength.REGULAR;
    
    MEDEDJI Setondji's avatar
    MEDEDJI Setondji committed
            else if ( strength >= 100 ) {
                result = Strength.STRONG;
    
    MEDEDJI Setondji's avatar
    MEDEDJI Setondji committed
            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);
    
    MEDEDJI Setondji's avatar
    MEDEDJI Setondji committed
        //}