Comparing two encrypted string with blowfish - php [duplicate] - php

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

Related

how to decrypt md5 password in php? [duplicate]

This question already has answers here:
Is it possible to decrypt MD5 hashes?
(24 answers)
Closed 3 years ago.
i am creating one admin panel for my app but the main problem is that when i am displaying password to admin in plain text then it will creates problem ??
i have stored my password in md5 format in php ? how can i able to decrypt that code in plain text in php ?
i have tried several times with every possibilities, but i haven's find any right answer yet now ?
$string ="hello";
$password= md5 ($string);
i expect plain text password which is reverse of encryption, that is decryption
In Theory no you can't. MD5 is ONE WAY hash algorithm. The original string is (lost) throught transformations. The sequrity of MD5 is compromised but you can not "decrypt or reverse" it. You can use a Rainbow Tables and try to find a match. Why you want to see User Password in clear text? The reason of hashing (encryption but without decryption key) is to protect privacy by turning personal information into “for your eyes only”, it's meens only User shoud be know the Password.
Md5 is a hash algorithm, sometimes incorrectly referred to as “one way encryption”. There is no way to get the original string back.
Also, why would you like to show the password in plain text? That can be a serious security issue. The purpose of hashing is to make sure the user writes the same password every time without anyone else knowing what the password is.

Neccesary to fetch hash from database ? password_hash bcrypt [duplicate]

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.

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

to de-encrypt from the text generate by bin2hex? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP 2-way encryption: I need to store passwords that can be retrieved
I am working with encrypt the password:
php> echo bin2hex(mhash(MHASH_SHA1,'test'));
a94a8fe5ccb19ba61c4c0873d391e987982fbbd3
My question is if I have a94a8fe5ccb19ba61c4c0873d391e987982fbbd3 How Can I get back the test.
Are the function to de-encrypt?
your have to understand the diff between a hash function an encryption.
Hashes are one way. You can't convert back. Checking passwords on login usually works by hashing the password from login, too and then just check if hashes are the same.
Using SHA1 it is easy to convert some text into a hash, but going the other way is very, very time consuming, which is one reason why it's good to use for encryption, and in your example passwords.
You may have some luck with this site -
http://www.md5decrypter.co.uk/sha1-decrypt.aspx
It has a list of common hashes and your example 'test' was easily found.
Why do you want to decode the hash output? You can check the password by hash, instead of trying to decode it. By the way, you can't decode a hash, because it loses information when it gets coded. if you want to encrypt/decrypt you should use MCrypt or another encryption class

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