mrplantplant / wordpress-auth
在其他PHP项目中使用WordPress密码认证,例如在迁移到其他平台时
v1.0
2024-02-12 15:36 UTC
This package is not auto-updated.
Last update: 2024-09-24 20:26:25 UTC
README
使用此包将给定的密码与WordPress散列字符串进行比较。我个人的用例是在迁移远离WordPress时,但不想让我们的用户重置他们的密码。我将从WordPress数据库导入用户到我的新数据结构中,带有用户类型标识符(因此我们知道哪个用户需要哪种认证方法)。在登录成功后,代码知道正确的密码,并且可以传递到您的新散列方法。
如果您需要关于新密码散列方法的灵感,请查看 password_hash()。特别关注 此注释 以增加额外的安全性。
用法
非常简单,创建一个新的 WPAuth\WordPressAuth
实例,并按照以下方式使用其 authenticate()
方法。
<?php
$authManager = new MrPlantPlant\WPAuth\WordPressAuth();
// Returns true on a successful match, false on mismatch
if ($authManager->authenticate($givenPassword, $storedHash)) {
// Now rehash $givenPassword with your new auth method and save it in your data source!
echo 'success!'
} else {
echo 'password mismatch';
}
?>