I hash or encode my password using hash sha256 in PHP. I want to decode it. I doesn't use any key or salt

3k Views Asked by At

I hashing my password using below method in PHP

$password=hash('sha256','123');

Now i want to decode it, how it is possible? I doesn't use any key or salt.

<?php
$password=hash('sha256','123');
echo $password;
$decdoe=base64_decode($password);
echo $decdoe;
?>
1

There are 1 best solutions below

9
ALPHA On

base64_decoding means decrypting a file using base64 algorithm. This is called encrypting. Hashing is a different case. when hashing what you hash cannot be recreated. so the purpose of hashing is to check the integrity of a file in this case the password. that means if u hash a password at the registration u will save the hashed part in the password field as password. Now when you re check it you need to check by hashing the user input password again with the value in your database. So using this code below

$hashed_password = password_hash($password, PASSWORD_DEFAULT);
// hash a password and store it into database

if(password_verify($password, $hashed_password)){ // here $password means user input when loggin $hashed_password is the hash from the database relevant to trying loggin 

}else{
 //throw error msg
}