'use bcrypt() in jquery or javascript

this code is written in validation.js to validate the all laravel change password forms dynamically

$.validator.addMethod("matchp", function(value, element)
{

 var dbpass = $("#old").val();  
// #old value is fetch from database in type=hidden in frontend and its in bcrypt format.



var txtpass = bcrypt($("#oldpass").val());  
// #oldpass value is fetch from frontend its user value and it sholud convert in bcrypt format.  

// So that we can compare it to verify the old password while changing the old password.


    // Check for equality with the password inputs
    if (dbpass != txtpass ) {
        return false;
    } else {
        return true;
    }

}, "Your Passwords Must Match");


Solution 1:[1]

Bcrypt function means an algorithm which gives different hash everytime for a unique string with some different salt. So it is not possible to validate it by using any JS Validation Plugin. Of course, you can check different input field values without using any hashing technique, like in the same way when validating password and confirm password fields.

If you are really required to use bcrypt at client-side, use a static salt.

Updated, if you are using @Nevins-b JavaScript Bcrypt plugin then you can do it by using same salt to validate different fields.

Hope this is satisfactory to your question.

Solution 2:[2]

That won't work because Laravel passwords are also salted.

What I would do is

  • Pass #oldpass un-encrypted to your back-end using ajax
  • On your back end compare the #oldpass with the current password using Hash::check

    if(Hash::check($request->oldpass, Auth::user()->password)){ return true;
    }else{ return false; }

Dont forget to add the facades to the top of your Laravel controller

use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Diego Poveda