| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace App\Module\User\Validator;
- use App\Module\Sys\Config;
- use App\Module\User\Services\User;
- use UCore\Validator;
- class Google2FA extends Validator
- {
- public function validate(mixed $value, array $data): bool
- {
- $userField = $this->args[0];
- $scene = $this->validation->getName();
- $user_id = $data[$userField];
- return self::check($user_id, $value, $scene);
- }
- /**
- * 检查
- *
- * @param $user_id
- * @param $value
- * @return bool|int
- * @throws \PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException
- * @throws \PragmaRX\Google2FA\Exceptions\InvalidCharactersException
- * @throws \PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException
- */
- static public function check($user_id, $value, $scene = '')
- {
- $info = User::infoinfo($user_id);
- $google2fa = new \PragmaRX\Google2FA\Google2FA();
- if (APP_DEBUG) {
- if ($info->google2fa_secret === '8888888888') {
- if ($value == '123456') {
- return true;
- }else{
- return false;
- }
- }
- }
- $check = \App\Module\User\Services\Google2Fa::must_check($info, $scene);
- if($check){
- $f = true;
- }
- if (empty($info->google2fa_secret)) {
- if ($f) {
- return false;
- }
- return true;
- }
- $valid = $google2fa->verifyKey($info->google2fa_secret, $value);
- return $valid;
- }
- }
|