What Does This Piece Of PHP do? (password decryption) [duplicate] - php

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.

Related

how password_verify() function actually works in PHP [duplicate]

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.

Md5 hash encryption and decryption

I have a confusion regarding md5.
I know that we cannot decrypt MD5 without attempting something like brute force hacking which is extremely tough.
Now, For one md5 hash i visit this website. MD5Online
For curiosity i decrypt that encrypted password to and i got the decrypted password.
Then i tried 4-5 password which are previously stored in my database and this site decrypted all of them.
Then i tried with below code.
<?php
$password = 'cool#123#!';
$secure_md5password = md5($password);
echo $secure_md5password;
?>
i got this md5 hash : 6234c13c3e1b965dbdd32d604151bd1b
I tried this hash in decryption of this site and i got 'cool#123#!'.
I tried with other toughest passwords also.
So now i'm confuse about md5 algorithm. Is that website doing brute force or any thing and can we use any code in php which that site is using.
I visit these links for answer but i can't find the answer.
1).encrypt-and-decrypt-md5
2).is-md5-decryption-possible
3).how-to-decrypt-an-md5-string-in-php
MD5 has been proven to be a weak algorithm. As all your 'passwords' are basic, the website has already stored each password with a hash that was cracked long ago.
You cannot decrypt a hash, but you can brute-force and find out what it is.
Read more here:
https://en.wikipedia.org/wiki/MD5
and
here:
https://security.stackexchange.com/questions/19906/is-md5-considered-insecure
EDIT: Saw that you updated your question.
Assuming that you were to have a complex password of 'ajfn3inf'
and you were to hash it. Running a md5 cracker will be easy to unhash it due to it's relatively short length and the power of GPU's to crack a hash. Read the links above to understand more about MD5.
That website is probably using rainbow tables.
Information about this topic:
https://en.wikipedia.org/wiki/Rainbow_table
Simple said: if they ever brute forced a hash, they'll save the hash and the password in a table.
When someone enters a hash, they'll search the table and retrieve the unhashed value.
Yes, that is done by brute force.
I'm sure that if your password is more than 12 characters, then this site is its unbroken.md5 is outdated and no longer used.
Instead, use system for encrypting password_hash
http://php.net/manual/ru/function.password-hash.php
you can use salt with md5. and put validation for strong password using strong password policy.

With the salt as part of a Blowfish hash how is it more secure [duplicate]

This question already has answers here:
Why does salting a hashed password increase security?
(2 answers)
Closed 8 years ago.
Edit: This question is not about what adding salt to a hash is, how to do it, nor how it increases security.
I wrote the following code:
<?php
$salt = '';
$salt_alphabet = str_split('aAbBcCdDeEfFgGhHiIjJkKlLmM.nNoOpPqQrRsStTuUvVwWxXyYzZ/');
$salt_prefix = (version_compare(PHP_VERSION, '5.3.7') < 0) ? '$2a' : '$2y';
foreach (array_rand($salt_alphabet, 20) as $alphameric) {
$salt .= $salt_alphabet[$alphameric];
}
if (defined('CRYPT_BLOWFISH') and CRYPT_BLOWFISH) {
echo crypt('thisisasuperpassword', $salt_prefix . '$07$' . $salt . '$$');
}
?>
Which outputs a Blowfish hash like so:
$2y$07$acEfghiKL.OprtuwyYZ/$.j7uui28rXLPyAcDzGBfQbbvQL6a.kk2
If someone gets this hash, how is having the salt available in the hash itself secure?
People say Blowfish is the most secure encryption there is, but hash encryption like SHA-256 doesn't display what salt was used or not in the hash itself, which would seem to be more secure. Isn't the point of salt in hashing to add randomness to the hash, if you have the randomness as part of the hash, how can it still be more secure?
As with the hash above, "acEfghiKL.OprtuwyYZ/$" is the salt, plain as day, right there in the hash itself. All someone would have to do is add this salt to the values they already have in their rainbow table, hash database, or what have them, and there you go, the purpose of the salt is defeated.
Or is it not somehow?
As an example, once you load a database into an array all you'd have to do is:
<?php
foreach ($hashes as $hash) {
$salt = explode('$', $hash)[3];
// Proceed to use the salt to crack the hash
}
?>
This seems like a glaring security problem, how is it not?
Or what am I doing wrong?
There are things, called rainbow tables. These are huge hash databases pre-generated with lots of passwords. If you don't add a salt, one can easily lookup your hash in a rainbow table and hack it in seconds.
Basically, instead of brute-forcing a password, all of those combinations that you'd use in brute-force are already in the database, optimized for super fast search. But once you add salt, that adds length and randomness to the password and makes it impossible to find in a rainbow table.
Blowfish is encryption, sha is hashing. The big difference is that encryption is reversible while hashing is not supposed to be.
The same password will always result in the same hash, so you don't need to store the password anywhere.
If you add random strings to a password, then encrypt the result, the outcome will be not reproducable and your password is useless.
If you are salting the password for hashing, you add security, because what ever technique is used to reverse calculate the hash, all possible results will be the original password + salt
But the salting has to be reproducable as well

Secure way to encrypt password [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Secure hash and salt for PHP passwords
Is this a secure way to encrypt the passwords to store in a mysql database:
md5(sha1($password))
Thanks.
What you are doing here is hashing, not encrypting.
Hashing has the purpose of not storing the password itself in the database, so that if the database is stolen the attacker will not gain knowledge of all user passwords.
Hashing should be used in conjunction with salting the hashes, because otherwise it will be relatively easy for an attacker who has gained access to the database to crack the weak passwords stored there.
Also, hashing the same input twice (as your example does with md5 and sha1) does not offer any significant benefit.
Generate random salt for each password and compute password digest with HMAC-SHA1. The salt is used as key and password is used as message. The salt and digest are stored into database.

MD5 password decryption [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Is it possible to decrypt md5 hashes?
Reversing an MD5 Hash
hi there is any way to decrypt md5 password field to allow user to edit password in form using javascript. or php.
MD5 is one way hashing algorithm - not a means of encrypting. As such, there's no means of decrypting it - only checking to see if another source input has the same hash.
No, there is no way, since hashing is not a reversible operation.
Your question is not very clear, but recovery of the origional string for hashes can be done with rainbowtables: http://en.wikipedia.org/wiki/Rainbow_table
(if the hash was salted, this will become troublesome ofcourse)
I wrote an app a few years back that brute-forces MD5 hashes against wordlists and previously-cracked MD5 hashes it finds via search engines, see if it comes up with anything for you:
http://bigtrapeze.com/md5/

Categories