Duplicate hash method for password in .NET

Here is the library: http://www.zer7.com/software/cryptsharp

And this is “howtouse”:

    public override bool ValidateUser(string name, string password)
    {
        if (string.IsNullOrWhiteSpace(name))
            return false;
        if (string.IsNullOrWhiteSpace(password))
            return false;

        // this is just fetching the hash from the WP-database using BLToolkit. You can use any other way to get the hash from db ;)
        UserData ud = null;
        using (Db db = new Db())
        {
            db.SetCommand(@"SELECT id, user_pass FROM wp_users WHERE user_login=@user_login AND user_status=0",
                db.Parameter("user_login", name)
            );

            ud = db.ExecuteObject<UserData>();

        }

        if (null == ud)
            return false;
        // !!!! HERE IS CHECKING !!!
        // LIB USAGE:
        return CryptSharp.PhpassCrypter.CheckPassword(password, ud.user_pass);
    }

This code is a part of custom MembershipProvider.

Leave a Comment