Jump to content

md5 hashes are they only alphanumeric?


monkeytooth

Recommended Posts

I have a user input string via GET variable that I want to always make sure falls within the constraints of type of variable its set for, which is a md5 hash.

So I want to put together using preg_match or something using a regex construct (even though I suck with regex) to verify that all the characters in the string are valid characters for a md5 hash, where if its not then I want to kick back an error. The idea of making something like that isnt the issue for me so much as not knowing whether or not an md5 has is strictly alphanumeric or if it can possibly even if one in a million chance have something else from an underscore to a exclamation point or other characters. Ive tried to find out searching google and other sites for an answer but my search terms I guess are way to open to find something distinctly close to what I am looking for answer wise, so I figured I'd give you guys a shot see if anyone knows.

Link to comment
https://forums.phpfreaks.com/topic/232231-md5-hashes-are-they-only-alphanumeric/
Share on other sites

so if its 0-9 a-F whats the best way to handle the through regex, as I said before I'm kinda horrible with putting a regex statement together. Not worried about length so much of it as I am just making sure the string is a valid hash

well they are chars, and we know the charset now.

 

preg_match('#^[a-z0-9]{32}$#i', $_GET['something']);

 

somethign like what should work I think.

 

Actually, since the letters only go to F, you don't need to look all the way to z...

preg_match('#^[a-f0-9]{32}$#i', $_GET['something']);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.