Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Add validator for custom hashes #606

Closed
slavafomin opened this issue Nov 27, 2016 · 2 comments
Closed

Feature request: Add validator for custom hashes #606

slavafomin opened this issue Nov 27, 2016 · 2 comments

Comments

@slavafomin
Copy link

Hello!

Thank you for this great library!

However, I would propose to introduce generic validator for different types of hashes. Right now, we have isMD5() validator, which is great, but there are no validators for other hash types, like sha256.

I would suggest the following API:isHash(str, algorithm).

We could call it like this: isHash('6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b', 'sha256').

Here's the list of most popular hash functions (algorithms): http://stackoverflow.com/q/16393650/1056679.

The original isMD5() could be deprecated over time in favor of isHash(str, 'md5').

What do you think?

Thanks!

@chriso
Copy link
Collaborator

chriso commented Nov 27, 2016

Great idea.

It could be something simple like:

var lengths = {
  md5: 32,
  sha1: 40,
  sha256: 64,
  // etc
}

function isHash(str, algorithm) {
  return validator.isHexadecimal(str) && str.length === lengths[algorithm];
}

@chriso
Copy link
Collaborator

chriso commented Sep 9, 2017

Fixed by #711.

@chriso chriso closed this as completed Sep 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants