Php 确定是否在Laravel Fortify中使用了恢复代码
是否可以确定在Laravel Fortify中是否已经使用了恢复代码?据我所知,没有现成的,但是,您可以自己实现一些功能 基本工作流可能如下所示:Php 确定是否在Laravel Fortify中使用了恢复代码,php,laravel,laravel-fortify,Php,Laravel,Laravel Fortify,是否可以确定在Laravel Fortify中是否已经使用了恢复代码?据我所知,没有现成的,但是,您可以自己实现一些功能 基本工作流可能如下所示: try { // grab the codes for the currently authenticated user $codes = json_decode(decrypt(auth()->user()->two_factor_recovery_codes), true); // if the provid
try {
// grab the codes for the currently authenticated user
$codes = json_decode(decrypt(auth()->user()->two_factor_recovery_codes), true);
// if the provided code exists in the array of codes stored in the DB for the authenticated user
if (in_array($code, $codes)) {
// remove the associated code and reindex the array
$codes = array_values(array_diff($codes, [$code]));
// optionally add a new recovery code
array_push($codes, Laravel\Fortify\RecoveryCode::generate());
// save the recovery codes back to the database
auth()->user()->two_factor_recovery_codes =
encrypt(json_encode(array_values($codes)));
auth()->user()->save();
}
} catch (DecryptException $e) {
echo $e->getMessage();
} catch (EncryptException $e) {
echo $e->getMessage();
}
据我所知,没有现成的东西,但是,你可以自己实现一些东西 基本工作流可能如下所示:
try {
// grab the codes for the currently authenticated user
$codes = json_decode(decrypt(auth()->user()->two_factor_recovery_codes), true);
// if the provided code exists in the array of codes stored in the DB for the authenticated user
if (in_array($code, $codes)) {
// remove the associated code and reindex the array
$codes = array_values(array_diff($codes, [$code]));
// optionally add a new recovery code
array_push($codes, Laravel\Fortify\RecoveryCode::generate());
// save the recovery codes back to the database
auth()->user()->two_factor_recovery_codes =
encrypt(json_encode(array_values($codes)));
auth()->user()->save();
}
} catch (DecryptException $e) {
echo $e->getMessage();
} catch (EncryptException $e) {
echo $e->getMessage();
}
我使用的是以下软件包:有一种方法可以获取恢复代码列表,但是没有像
used
这样的键来检查它们是否已被使用,并且使用过的代码也没有存储在任何地方。但是Fortify可以为您这样做。我的意思是,一旦其中一个代码已经被使用,它就会生成新的替换代码…对吗?我正在使用以下软件包:有一种方法可以获取恢复代码列表,但是没有像used
这样的键来检查它们是否已经被使用过,并且使用过的代码也没有存储在任何地方。但是请为您加强这一点。我的意思是,一旦其中一个已经被使用,它就会生成新的替换代码…对吗?这不是我要找的。我想循环浏览恢复代码,并向用户显示已经使用过的代码。Fortify如何知道是否使用了代码?@Polarie Fortify不会在开箱即用的情况下这样做。对上面的内容稍作调整即可满足您的要求。这不是我想要的。我想循环浏览恢复代码,并向用户显示已经使用过的代码。Fortify如何知道是否使用了代码?@Polarie Fortify不会在开箱即用的情况下这样做。对上述内容稍作调整即可满足您的要求。