1

I have an app in vb.net and I want to store a password in my database that is understandable from PHP. The creation in PHP is like this:

$hash = password_hash("mypassword", PASSWORD_BCRYPT);

The result looks like this:

$hash = '$2y$07$BCryptRequires22Chrcte/VlQH0piJtjXl.0t1XkA8pw9dMXTpOq';

and the code in php to validate a password looks likethis

if (password_verify('mypassword', $hash)) {     
    echo 'Password is valid!'; 
} else {     
    echo 'Invalid password.'; 
}

How can I replicate this code

$hash = password_hash("mypassword", PASSWORD_BCRYPT);

iv VB.Net, so the results will match exactly?

2
  • If you are capable to call a PHP script from VB.NET, and it is secure, then you can just let that script return the hash with one easy line of PHP code. It will even change when the implementation in PHP changes. Commented Dec 7, 2022 at 18:21
  • Have you tried Dim hash = BCrypt.Net.BCrypt.HashPassword("mypassword", 'BCrypt.Net.BCrypt.GenerateSalt(10)') Commented Dec 7, 2022 at 19:15

1 Answer 1

1

In the php line, you provided, you use the bcrypt algorithm to hash the password. This is a general hashing algorithm, not unique to php.

Im not very familar with VB.net, but this is what I found with a quick search:

' This example assumes the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.

Dim crypt As New Chilkat.Crypt2

' The BCrypt cost factor (work factor) can be set to a value from 4 to 31.
' The default value is 10.  We'll set it here explicitly to the default value
' to make this new property known.  This line of code can be omitted
' if the default value of 10 is desired.
crypt.BCryptWorkFactor = 10

Dim bcryptHash As String = crypt.BCryptHash("mySecretPassword")
Debug.WriteLine("BCrypt hash = " & bcryptHash)

' Sample output:
' BCrypt hash = $2a$10$H5kIVktMGzAPKGKNAe9DVu0iwEqfhv/o4MMJ/Dzw/MPy1leOE9NOK

' Note: Your output will be different because the BCryptHash method
' automatically generates a random salt. 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.