Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if string is a hash

I'm using SHA-512 to hash my passwords (with a salt ofcourse). I don't think that what I want is possible, but let's ask anyway.

Is there a way to check if a string is a SHA-512 (or another algorithm) hash already?

When a user logs in, I want to do a check on his password. If it's still in plain text, it should get converted to a secure form.

like image 384
Bv202 Avatar asked Apr 07 '26 17:04

Bv202


2 Answers

Your task is extremely simple and require no strings checking.

Just compare entered password with stored one first.
If matched - here it is, a plain password. So, you can start conversion process.

like image 50
Your Common Sense Avatar answered Apr 09 '26 07:04

Your Common Sense


As @zerkms already mentioned the string length is the most obvious thing you can test against. Also hashes usually are written in hexadecimal, so it only consists of the digits 0 to 9 and the characters a to f. Or as regular expression

/[0-9a-f]{64}/i
like image 24
KingCrunch Avatar answered Apr 09 '26 07:04

KingCrunch