Retrieving an encrypted password in PHP [duplicate] - php

This question already has answers here:
How do you use bcrypt for hashing passwords in PHP? [duplicate]
(11 answers)
How to decrypt hashed password using php?
(4 answers)
Closed 9 years ago.
The following code is what I've used to encrypt a password in PHP...
$password = sha1(sha1($_POST['password']).sha1("mySalt#$#(%"));
What code can I use so users can log in using what they typed?

sha1 is a hashing algorithm, not a 2-way encryption. You cannot retrieve the original password.
Hash the submitted password using the same algorithm.
Fetch, from your database, the password hash for the user in question.
Compare the two hashes. If they match, the credentials are OK.
Don't use sha1 for password hashing, it isn't safe enough
Use a unique salt per credential, don't reuse the same one each time.

You should use crypt for password hashing, sha1/md5 are too weak.
All you need:
function check_password($password) {
...//get db password to compare
if (crypt($post_password, $db_results[0]['password']) == $db_results[0]['password']) {
return true;
} else { return false; }
}

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.

PHP hash function [duplicate]

This question already has answers here:
Is SHA-256 Case Insensitive?
(4 answers)
Closed 5 years ago.
Recently I started to make an UCP for a game server but I come to a problem. The game server hash passwords with sha256 and salt. The hashed password look like this 399B77A0AD470496AE09579C2CA3FAF2F01E8A63D9F4ECFA6F60E32CE2E7E5E9
but the php hash function for sha256 give this hash 399b77a0ad470496ae09579c2ca3faf2f01e8a63d9f4ecfa6f60e32ce2e7e5e9.
When the user input and the password from database it's compared, they are not the same and user can't login.
How to ignore uppercase/lowercase or how to make the hash function to hash the input in uppercase?
Just do:
strtoupper($your-lower-case-hash)
Another option to Matias solution would be
if (0 === strcasecmp($phpHash, $mysqlHash)) {}
see http://php.net/manual/en/function.strcasecmp.php

Can I Decrypt md5 in php? [duplicate]

This question already has answers here:
Is it possible to decrypt MD5 hashes?
(24 answers)
Closed 7 years ago.
This is my encryption password.
$encrypted = md5($password);
Can I Decrypt it?
MD5 is a hash function, which are one-way functions (cannot be undone).
Whilst I would not recommend MD5 for password storage, if you want to verify that a password is correct you do not need to decrypt the hash. The idea is in order to verify a password is correct, rather than decrypting the hash, you encrypt the password given and compare the two hash values. If the two hash values are the same, then the two passwords are the same,

Comparing two encrypted string with blowfish - php [duplicate]

This question already has answers here:
PHP Crypt() Compare two crypted strings
(5 answers)
Closed 8 years ago.
I generated an encrypted string with using blowfish encryption function (crypt()) in php and stored it in database. How can I check correctness of submitted password then?
For eg. during registration, I defined my pass as "1234" and then generated a random key and then my blowfish encrypted password something like "$2a$08$xPIviMLmVMHLQdzb$$$$$.OdQVKDPJeK4KIcdqnngIgv41lILjKR." So, when user comes back, how can I check correctness of his/her password? Is there any comparing function of two encrypted string from the same base password or another efficient way? Thanks in advance.
Simply pass the user input from the form into the crypt function, with the hash in the database.
For example:
<?php
if (crypt($passwordFromPost, $hashedPasswordInDb) == $hashedPasswordInDb)
{
// User has been authenticated
}
Passwords are usually not encrypted but hashed. It is not possible to regenerate the original password from a hash.
To find out more about password hashing in PHP the manual is a good starting point PHP manual

Convert md5 encrypted password to decrypted password wordpress [duplicate]

This question already has answers here:
Is it possible to decrypt MD5 hashes?
(24 answers)
Closed 8 years ago.
I want to get real password which is converted by wordpress into md5 format.
For example,
my md5 password is - 62cc2d8b4bf2d8728120d052163a77df
Real password - demo123.
I want to get real password from md5 version.
I tried this but didn't give me what I want -http://md5encryption.com/
You cannot unhash a password. That is the whole reason you hash a password in the first place.
It is possible to 'brute' force a password, or use a rainbow table to lookup the password - but that is why you (hopefully) used a salt on the password to ensure the hash is unique.

Categories