Created
July 6, 2019 05:25
-
-
Save athiththan11/91f041fb6285235d2708580e914ce13c to your computer and use it in GitHub Desktop.
Default defective password validation method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DefaultDefectivePasswordValidator implements DefectivePasswordValidator { | |
private static List<String> crackedPasswords = new ArrayList<>(); | |
private static DefaultDefectivePasswordValidator dPasswordValidator = new DefaultDefectivePasswordValidator(); | |
private static final Logger log = LoggerFactory.getLogger(DefaultDefectivePasswordValidator.class); | |
private DefaultDefectivePasswordValidator() { | |
} | |
public static DefaultDefectivePasswordValidator getInstance() { | |
return dPasswordValidator; | |
} | |
/** | |
* initialize defective password values from the given text file | |
*/ | |
@Override | |
public void initValues() { | |
crackedPasswords = new ArrayList<>(); | |
try { | |
crackedPasswords = Files.readAllLines(Paths.get(DefectivePasswordValidatorConstants.PASSWORD_FILE_PATH), | |
StandardCharsets.UTF_8); | |
} catch (IOException e) { | |
log.error("Exception occured while reading and initializing values from " | |
+ DefectivePasswordValidatorConstants.PASSWORD_FILE_NAME, e); | |
} | |
} | |
/** | |
* validate method | |
*/ | |
@Override | |
public boolean validate(Object credential) { | |
return !crackedPasswords.contains((String) credential); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment