Skip to content
Snippets Groups Projects
Select Git revision
  • 9915409c44149a5b1bb1374e797f56a5a5e9ab2c
  • main default protected
2 results

AuthenticationByPasswordService.java

Blame
  • Forked from LABOUREL Arnaud / M1 INFO FSI TP Template
    Source project has a limited visibility.
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    AuthenticationByPasswordService.java 1.79 KiB
    package interfacemanualmocking;
    
    import authentication.AuthenticationService;
    import authentication.Strength;
    
    public class AuthenticationByPasswordService implements AuthenticationService {
        private DirectoryInterface directory;
        private StrengthEstimationServiceInterface 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)
            if( strength >= 0 && strength <= 49 ) {
                return Strength.VERY_WEAK;
            }
            if( strength >= 50 && strength <= 79 ) {
                return Strength.WEAK;
            }
            if ( strength >= 80 && strength <= 99 ) {
                return Strength.REGULAR;
            }
            if ( strength >= 100 ) {
                return Strength.STRONG;
            }
    }
        private boolean isMatch(String identifier, String autenthicationData) {
            String match = directory.getMatch(identifier);
            return match.equals(autenthicationData);
        }
    
        //private StrengthEstimationServiceInterface dataStrenth(String autenthicationData) {
         //   int alphabetSize = 0;
           // int datasize = autenthicationData.length();
            //return strengthEstimationService.equivalentBitLength(alphabetSize, datasize);
        }