This question already has answers here:
How does password salt help against a rainbow table attack?
(10 answers)
How can bcrypt have built-in salts?
(5 answers)
Password hashing, salt and storage of hashed values
(4 answers)
Closed 3 months ago.
I am wondering about how password_verify() verifies the hash, I have reviewed the documentation and many answers in StackOverflow, but I didn't get the idea
because, as I understood, this function will compare the hash with entered password after hashing it again, and use the same salt and cost and algorithm,
but the question here: if anyone can separate the salt from the hashed password, then anybody also can try to use rehash and try to match, and the salt will be useless here. Am I right, or what?
The salt have to be generated randomly each time the fonction is used (and it's what this function does, and not accept custom salt anymore).
For example:
<?php
$password = "nothing";
echo password_hash($password, PASSWORD_DEFAULT);
echo PHP_EOL;
echo password_hash($password, PASSWORD_DEFAULT);
Give the response :
$2y$10$mdJRjsoc1vR11SKa2JDyS.qSlxja/a0SUPuXC1NKsRLkzmayKwjku
$2y$10$H2th6dRY/i.xZzXSGxDZ1uaiwZx6s0.FM0NXcBcBQ0E2aNEHCJ57m
It's the same password with differents results.
The hashed password is stored in a database or a file. In this case, an admin system (or someone who's hacked the database) can't say if the same password is used by differents users. Another point, rainbow tables can't be used with hashed password with salt. Only brut force can be done.
Using the same salt for all is not more secure than using simple hash algorytm.
Related
This question already has answers here:
How do I convert password hashing from MD5 to SHA?
(7 answers)
Closed 11 days ago.
I would like if it's possible to change the hashing method for an already hashed password. For example:
$password_input = '123456789';
$hashed_password = md5($password_input);
// The output would be 25f9e794323b453885f5181f1b624d0b
The result was made with the following online tool:
https://helloacm.com/md5/
The next step would be insert the hashed password into the database. When I do this the given hashed password will be in the users table. If I select that password, can I change the md5 hash by a sha-256? For example:
$md5_password = '25f9e794323b453885f5181f1b624d0b';
$sha256_password = hash('sha256', $md5_password);
If this would be possible, would it break the login function? I mean if I use password_verify method, will it return true?
You will not get password back from md5, you can't unhash one way hash algorithms.
What we do - incorporate re-hashing in login flow.
User logins to your system with old hash password
You detect, that this user needs re-hash
While still having sent plain text password you hash it with new algorithm and save to database
Next time user logins with newly hashed password without problems
This question already has an answer here:
Trying to understand password_verify PHP
(1 answer)
Closed 5 years ago.
I use PHP's password_hash and bcrypt algorithm to hash my passwords. They are in MySQL database.
password_hash($password, PASSWORD_BCRYPT);
As obvious every hash generated by this function is different. But is it really necessary, to identify user by email/login or something to grab his hash from database and then verify it with PHP's password_verify()?
Is it really necessary to make this query and then check?
I mean, is it possible to check hash before, and after only do query to check if it matches this one in MySQL?
Or something else maybe? I remember years ago I used something like checking inside query, like
WHERE login = $login and pass = PASSWORD($password)
Especially I mean this PASSWORD($password)?
Is there other option than fetch user's hash from Database and then verify this hash with password_verify()?
Yes, it's necessary. You need the unique salt generated during hashing, encoded as part of the hash, to do the comparison. That's also exactly why this algorithm is so strong for password storage.
This question already has answers here:
Secure hash and salt for PHP passwords
(14 answers)
Closed 9 years ago.
I've got a little question here because I'm creating a log in and register system. A developer at my school told me to salt secure passwords. I agree on that point but he said I needed to create the salt out of a timestamp but how to do it? Currently I'm doin' this:
$password = hash('sha512', $password . $salt);
and the salt just like:
$salt = "xHkosbGhsfT77239GhsvH";
This stands litteraly in my configuration so it's not good...
Does anyone have some tips? Any idea how to do it, so if any of you do share it with me!
Thanks.
It is better to generate a unique salt for each user and keep them in your user table. So, for password checking, just fetch the user salt from database and use it. It is much safer than using a single salt for hole database.
You can use hash_hmac() function which needs three arguments (See documentation). I use it like this:
hash_hmac('sha512', $password . $salt, SITEKEY);
sha512 is my preferred hash function which generates 128B long strings
$password is user password
$salt is unique string generated for each user and stored in the database in the same row for user
salt is generated as: bin2hex(openssl_random_pseudo_bytes($bits)) (See documentation)
SITEKEY is unique string for each site I make
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
what is best possible way of salting and storing salt?
Improve password hashing with a random salt
Assuming that using a correct algorithm for password hashing and generating different salts for each password...
Is it a security risk to store salts separately from password hashes? For ex. in a database table, storing password hashes in one column, and password salts in a separate column?
I saw strategies where the salt is embedded into the password hash itself, by using a specific algorithm. Later on the salt can be extracted from the password hash. Is this more secure?
From everything I have ever read and done, there is nothing wrong with storing the password hash and password salt in separate columns, and that is the most common way to do it.
The basic method for authentication should go something like this:
Retrieve user_id and password_salt using user supplied username or email
Concat user supplied password input with retrieved salt
Use hashing algorithm on combined string
Check created hash against the hash in the database
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Can I md5(sha1(password))?
$pass = md5($_POST["pass"].sha1($_POST["pass"]))
I saw this somewhere and was confused. Does this read a password and decrypt it using sha1 then md5 or reverse? Or is there some other things that I'm missing?
It is hashing $_POST['pass'] with the sha1 algorithm, then combining that hash with $_POST['pass'], then hashing the resulting combined string with the md5 algorithm.
Why, I have no idea.
What it is doing is that it is concatenating the password with the sha1 hashed version of it (one of these is the salt) then hashing it into an MD5 value.
Actually it hashes the password.
It concatenates the clear password with the sha1'd password. Then it Md5 the whole thing
It hashes it with MD5.
Takes your password from the form, adds a salt and hashes the whole thing.
Note:
The 'salt' is a another hash. It is not a good idea to do it this way, a salt should be a random value that you have made that keeps the password secure.