PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, January 8, 2022

[FIXED] hash function on laravel cant decrypt string given from form

 January 08, 2022     bcrypt, encryption, laravel, laravel-8     No comments   

Issue

Im currently creating an application that requiring me to use the Bcrypt Hash function on laravel, but for some reason it always says that the string given to decrypt is 'false' when i do dd, but if i use plain-text, it says 'true' with dd.

for more context i will give the code related

Encryption:

  $encryptionKey = "PNJiX9RhLmnzJw2vRT1kolbYd3iwj96z";
        // $new_hash=Hash::make($encryptionKey);
        $new_hash = Hash::make($encryptionKey, [
            'rounds' => 12,
        ]);

Decryption with plain text that gives 'true' result(I check with online decrypting tools too):

dd(Hash::check( 'PNJiX9RhLmnzJw2vRT1kolbYd3iwj96z', '$2y$12$1tdSV0MQFuXSTisGoSPnw.efdnl9.Hk8x907U5TcgJ78mobozhUoK'));

Decryption with plain text that gives 'false' result:

$this->validate($request, [
            'key' => 'required',
        ]);
        $hashedPassword = 'PNJiX9RhLmnzJw2vRT1kolbYd3iwj96z';
        $encryptionOldKey = $request->key;
dd(Hash::check( $encryptionOldKey, $hashedPassword));

Blade file related to form decryption:

<div class="modal-body">

<form action="{{ url('/home/decrypt', $file->id ) }} " method="POST" enctype="multipart/form-data">
                                                    {{ csrf_field() }}

<div class="form-group">
                                                        <b>Key</b>
    <input type="text" class="form-control" name="key" >
                                                    </div>

                                            </div>
         <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel <i class="ni ni-fat-remove"></i></button>
<button type="submit" class="btn btn-primary">Decrypt<i class="ni ni-check-bold"></i></button>
                                            </div>

</form>

Solution

solution

Always (Hash::make) accept plain-text(original password) not encrypted/hased one.

For reference:

use Illuminate\Support\Facades\Hash;

$newPassword='12345678'; // original/plain-text
$hashedPassword=Hash::make($newPassword);

if (Hash::check($newPassword, $hashedPassword)) {
    // The passwords match...
}


Answered By - Engr Talha
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing