Make equals overridable to support different comparison logic #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adding an override-able "equals" method enables you to switch out comparison logic.
I love the look and feel of the library but one of my top priorities is security, so I wanted to encrypt the passcode before saving, and then later use the encrypted user input to compare the two.
Instead of building the encryption into the library I thought a better approach is to just expose the comparison method so that the inherited classes can override it.
For example I'm already using a library called SecurePreferences--which makes it easy to implement an encrypted version of SharedPreferences--in my project. So I simply need to extend
PasscodeView
and override theequals
method. The end result looks something like this:First, override the listener so that it encrypts the passcode before saving:
Second, compare using the overridden
equals()
method:So far it's working fine for me without having to change much to the original library. What do you think?