Search code examples
c#phppasswordscryptography

looking for c# equivalent of php's password-verify()


I need to import a bunch of user accounts Moodle into a system written in c#.

Moodle uses password_hash() function to create hashes of passwords. I need to be able to verify these passwords in c#.

In other words I looking for a c# implementation of PHP's password verify function ( http://www.php.net/manual/en/function.password-verify.php ).

I've googled a bit but couldn't really find anything close, so I am asking in hopes of avoiding reinventing the wheel :-)

Thanks!


Solution

  • Got it!

    First install CryptSharp via NuGet Package. (Use the 2.0 "official" package), and by the way, BCrypt.net didn't work for me.

    Then:

    using CryptSharp;
    bool matches = Crypter.CheckPassword("password goes here", "hash goes here");
    

    Note that hash should start with something like: "$2y$..."

    Works like a charm! :-)