这是图书馆:http://www.zer7.com/software/cryptsharp
这是“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);
}
此代码是自定义MembershipProvider的一部分。