Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save athiththan11/91f041fb6285235d2708580e914ce13c to your computer and use it in GitHub Desktop.
Save athiththan11/91f041fb6285235d2708580e914ce13c to your computer and use it in GitHub Desktop.
Default defective password validation method
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